Skip to content

Commit 9768f0f

Browse files
committed
gdb: install a 'pyocd' executable on installation that runs gdb server
This change moves the main content from the gdb_server.py tool into the main codebase and adds a console entry_point to the python package definition. The entry_points specification is well-understood by tools like pip and is also familiar to package maintiners for various distributions. Some cleanup (but not complete cleanup) was performed on the code that was moved, but everything should be functionally equivalent to how it was previously.
1 parent 1bd3e2c commit 9768f0f

File tree

6 files changed

+84
-51
lines changed

6 files changed

+84
-51
lines changed

MANIFEST.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
recursive-include binaries *
2+
recursive-include elf_files *
3+
recursive-include pyOCD *.ld *.txt *.c *.bat

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ You have a few options here:
5050

5151
Standalone GDB Server
5252
---------------------
53-
<p>pyOCD now provide a manual HOW_TO_BUILD.md in root folder to explain how to build pyOCD into single executable gdb server program.</p>
54-
[GCC ARM Toolchain](https://launchpad.net/gcc-arm-embedded) also provided a pre-build version of pyOCD gdb server at [Misc tools related to gcc arm embedded tool chain](https://launchpad.net/gcc-arm-embedded-misc/pyocd-binary)
5553

54+
When you install pyOCD via pip, you should be able to execute the
55+
following in order to start a GDB server powered by pyOCD:
56+
57+
```Shell
58+
pyocd
59+
```
60+
61+
You can get additional help by running `pyocd --help`.
5662

5763
### Recommended GDB and IDE setup
5864
The GDB server works well with Eclipse and the GNU ARM Eclipse OpenOCD plug-in.
File renamed without changes.

tools/gdb_server.py pyOCD/tools/gdb_server.py

+66-48
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
from pyOCD.board import MbedBoard
2525
import argparse
2626

27-
LEVELS={'debug':logging.DEBUG,
28-
'info':logging.INFO,
29-
'warning':logging.WARNING,
30-
'error':logging.ERROR,
31-
'critical':logging.CRITICAL
32-
}
27+
LEVELS = {
28+
'debug': logging.DEBUG,
29+
'info': logging.INFO,
30+
'warning': logging.WARNING,
31+
'error': logging.ERROR,
32+
'critical': logging.CRITICAL
33+
}
3334

3435
supported_targets = pyOCD.target.TARGET.keys()
3536
debug_levels = LEVELS.keys()
@@ -51,54 +52,71 @@
5152
group = parser.add_mutually_exclusive_group()
5253
group.add_argument("-ce", "--chip_erase", action="store_true",help="Use chip erase when programming.")
5354
group.add_argument("-se", "--sector_erase", action="store_true",help="Use sector erase when programming.")
55+
# -Currently "--unlock" does nothing since kinetis parts will automatically get unlocked
5456
parser.add_argument("-u", "--unlock", action="store_true", default=False, help="Unlock the device.")
5557
# reserved: "-a", "--address"
5658
# reserved: "-s", "--skip"
5759
parser.add_argument("-hp", "--hide_progress", action="store_true", help = "Don't display programming progress." )
5860
parser.add_argument("-fp", "--fast_program", action="store_true", help = "Use only the CRC of each page to determine if it already has the same data.")
59-
args = parser.parse_args()
6061

61-
# Notes
62-
# -Currently "--unlock" does nothing since kinetis parts will automatically get unlocked
6362

64-
# Determine programming mode
65-
chip_erase = None
66-
if args.chip_erase:
67-
chip_erase = True
68-
elif args.sector_erase:
69-
chip_erase = False
70-
71-
# Set gdb server settings
72-
gdb_server_settings = {
73-
'break_at_hardfault' : args.break_at_hardfault,
74-
'step_into_interrupt' : args.step_into_interrupt,
75-
'break_on_reset' : args.break_on_reset,
76-
'persist' : args.persist,
77-
'soft_bkpt_as_hard' : args.soft_bkpt_as_hard,
78-
'chip_erase' : chip_erase,
79-
'hide_programming_progress' : args.hide_progress,
80-
'fast_program' : args.fast_program,
63+
def get_chip_erase(args):
64+
# Determine programming mode
65+
chip_erase = None
66+
if args.chip_erase:
67+
chip_erase = True
68+
elif args.sector_erase:
69+
chip_erase = False
70+
return chip_erase
71+
72+
73+
def get_gdb_server_settings(args):
74+
# Set gdb server settings
75+
return {
76+
'break_at_hardfault' : args.break_at_hardfault,
77+
'step_into_interrupt' : args.step_into_interrupt,
78+
'break_on_reset' : args.break_on_reset,
79+
'persist' : args.persist,
80+
'soft_bkpt_as_hard' : args.soft_bkpt_as_hard,
81+
'chip_erase': get_chip_erase(args),
82+
'hide_programming_progress' : args.hide_progress,
83+
'fast_program' : args.fast_program,
8184
}
8285

83-
gdb = None
84-
level = LEVELS.get(args.debug_level, logging.NOTSET)
85-
logging.basicConfig(level=level)
86-
if args.list_all == True:
87-
MbedBoard.listConnectedBoards()
88-
else:
89-
try:
90-
board_selected = MbedBoard.chooseBoard(board_id = args.board_id, target_override = args.target_override, frequency = args.frequency)
91-
with board_selected as board:
92-
# Boost speed with deferred transfers
93-
board.transport.setDeferredTransfer(True)
94-
gdb = GDBServer(board, args.port_number, gdb_server_settings)
95-
while gdb.isAlive():
96-
gdb.join(timeout = 0.5)
97-
except KeyboardInterrupt:
98-
if gdb != None:
99-
gdb.stop()
100-
except Exception as e:
101-
print "uncaught exception: %s" % e
102-
traceback.print_exc()
103-
if gdb != None:
104-
gdb.stop()
86+
87+
def setup_logging(args):
88+
level = LEVELS.get(args.debug_level, logging.NOTSET)
89+
logging.basicConfig(level=level)
90+
91+
92+
def main():
93+
args = parser.parse_args()
94+
gdb_server_settings = get_gdb_server_settings(args)
95+
setup_logging(args)
96+
97+
gdb = None
98+
if args.list_all == True:
99+
MbedBoard.listConnectedBoards()
100+
else:
101+
try:
102+
board_selected = MbedBoard.chooseBoard(
103+
board_id=args.board_id,
104+
target_override=args.target_override,
105+
frequency=args.frequency)
106+
with board_selected as board:
107+
# Boost speed with deferred transfers
108+
board.transport.setDeferredTransfer(True)
109+
gdb = GDBServer(board, args.port_number, gdb_server_settings)
110+
while gdb.isAlive():
111+
gdb.join(timeout=0.5)
112+
except KeyboardInterrupt:
113+
if gdb != None:
114+
gdb.stop()
115+
except Exception as e:
116+
print "uncaught exception: %s" % e
117+
traceback.print_exc()
118+
if gdb != None:
119+
gdb.stop()
120+
121+
if __name__ == '__main__':
122+
main()
File renamed without changes.

setup.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@
3939
author="samux, emilmont",
4040
4141
license="Apache 2.0",
42-
classifiers = [
42+
classifiers=[
4343
"Development Status :: 4 - Beta",
4444
"License :: OSI Approved :: Apache Software License",
4545
"Programming Language :: Python",
4646
],
47+
entry_points={
48+
'console_scripts': [
49+
'pyocd-gdbserver = pyOCD.tools.gdb_server:main',
50+
],
51+
},
4752
install_requires=install_requires,
4853
use_2to3=True,
4954
packages=find_packages(),
55+
include_package_data=True, # include files from MANIFEST.in
5056
)

0 commit comments

Comments
 (0)