├── .gitignore
├── LICENSE
├── README.md
└── src
├── EventGroup.py
├── FreeRTOS.py
├── GDBCommands.py
├── HandleRegistry.py
├── List.py
├── Queue.py
├── Task.py
├── Types.py
└── __init__.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 |
5 | # C extensions
6 | *.so
7 |
8 | # Distribution / packaging
9 | .Python
10 | env/
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | lib/
17 | lib64/
18 | parts/
19 | sdist/
20 | var/
21 | *.egg-info/
22 | .installed.cfg
23 | *.egg
24 |
25 | # PyInstaller
26 | # Usually these files are written by a python script from a template
27 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
28 | *.manifest
29 | *.spec
30 |
31 | # Installer logs
32 | pip-log.txt
33 | pip-delete-this-directory.txt
34 |
35 | # Unit test / coverage reports
36 | htmlcov/
37 | .tox/
38 | .coverage
39 | .cache
40 | nosetests.xml
41 | coverage.xml
42 |
43 | # Translations
44 | *.mo
45 | *.pot
46 |
47 | # Django stuff:
48 | *.log
49 |
50 | # Sphinx documentation
51 | docs/_build/
52 |
53 | # PyBuilder
54 | target/
55 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | FreeRTOS-GDB
2 | ============
3 |
4 | Python API Library for inspecting FreeRTOS Objects in GDB
5 |
6 | Basically, the FreeRTOS internal state is kind of hard to inspect
7 | when working with GDB. This project provides some scripts for GDB's
8 | Python API that make accessing some of these internals a little easier
9 | to inspect.
10 |
11 | ##Requirements:
12 |
13 | 1. You need to have the python API enabled in your version of GDB. This is a
14 | compile time option when building GDB. You should be able to do something
15 | like this:
16 | ```
17 | gdb> python print "Hello World"
18 | ```
19 |
20 | and get predictable results. If it throws an error - then you don't have
21 | python compiled in your version of GDB.
22 |
23 | 2. Need to be using FreeRTOS 8.0+. This code could probably be used with FreeRTOS
24 | version 7.0 or previous versions, but the current code doesn't support it.
25 |
26 | 3. You need to use the Handle Registry for Queue info to be any use.
27 | Note that this only works for Queue based objects and not
28 | for EventGroups
29 |
30 | 4. You need to put the FreeRTOS-GDB/src directory on your python path:
31 | ```
32 | $> export PYTHONPATH=~/src/FreeRTOS-GDB/src/
33 | ```
34 |
35 | How To Use:
36 | ```
37 | $> gdb ./bin/program.elf
38 | (gdb) c
39 | Program runs on embedded device, sets up tasks, and queues
40 |
41 | (gdb) source ~/FreeRTOS-GDB/src/FreeRTOS.py
42 | (gdb) show Task-List
43 | Name PRI STCK
44 | Ready List {0}: Num Tasks: 1
45 | IDLE 0 107
46 | Blocked List: Num Tasks: 11
47 | EMAC Task 1 239
48 | AFEC0 Task 1 295
49 | LDSENS Task 1 195
50 | AFEC1 Task 1 295
51 | LineSample Task 1 281
52 | DMAUART0 1 225
53 | Log Task 1 273
54 | BAT Task 1 169
55 | Rx Task 1 421
56 | Mng Task 2 551
57 | Cell Task 1 275
58 | Delayed {1}: Num Tasks: 5
59 | Tmr Svc 3 355 62254
60 | WLAN Task 1 205 13817
61 | Init Task 1 445 10015
62 | LED Task 1 179 7105
63 | DMACOM1 1 265 7065
64 | Delayed {2}: Num Tasks: 0
65 |
66 | (gdb) show Queue-Info mutex
67 | Num Queues: 6
68 | NAME CNT SEND RECEIVE
69 | LOG:LOCK 1 NONE NONE
70 | STREAM:LOCK 1 NONE NONE
71 | TWI:MUTEX 1 NONE NONE
72 | CC3000:LOCK 1 NONE NONE
73 | WLAN:LOCK 0 NONE NONE
74 | SPI:LOCK 1 NONE NONE
75 |
76 | (gdb) show Queue-Info queue
77 | Num Queues: 14
78 | NAME CNT SEND RECEIVE
79 | TmrQ 0 Tmr Svc
80 | LOG:MSGPOOL 12 NONE NONE
81 | LOG:MSGQ 0 Log Task
82 | TWI:QUEUE 0 NONE NONE
83 | SPI:QUEUE 0 NONE NONE
84 | DMAAFEC:POOL 1 NONE NONE
85 | DMAAFEC:QUEUE 0 AFEC0 Task
86 | DMAAFEC:POOL 1 NONE NONE
87 | DMAAFEC:QUEUE 0 AFEC1 Task
88 | COM:TXPOOL 3 NONE NONE
89 | COM:TXQ 0 NONE NONE
90 | COM:RXPOOL 5 NONE NONE
91 | COM:RXQ 0 NONE NONE
92 | FATFS:MUTEX 0 NONE NONE
93 |
94 | ```
95 |
96 | @note - the NONE's above may just be empty strings.
97 |
98 | This code adds the following custom GDB commands:
99 |
100 | * show List-Handle (symbol|address) [CastType]
101 | CastType is an optional argument that will cast all of the
102 | handles in a list to a particular type.
103 | * show Task-List
104 | * show Handle-Registry
105 | * show Handle-Name (symbole|address)
106 | * show Queue-Info [filter]
107 | filter can be "queue","mutex","semaphore", "counting", "recursive"
108 |
109 |
110 |
111 | @TODO
112 | =====
113 |
114 | * With GDB's Python API - it doesn't seem to handle code is separate
115 | files very well.
116 |
117 | * Currently, the EventGroup objects don't have an inspector.
118 | Work in progress - ideal solution would likely modify the struct
119 | of the Event Group to provide a similar piece of info that the
120 | Queue handle does so that we could use the same registry.
121 |
--------------------------------------------------------------------------------
/src/EventGroup.py:
--------------------------------------------------------------------------------
1 | # File: EventGroup.py
2 | # Author: Carl Allendorph
3 | # Date: 05NOV2014
4 | #
5 | # Description:
6 | # This file contains the implementation of a Event Group Inspector
7 |
8 |
9 | import gdb
10 | from List import ListInspector
11 | from Task import TaskInspector
12 |
13 | class EventGroupInspector:
14 | EvtGrpType = gdb.lookup_type("EventGroup_t")
15 |
16 | def __init__(self, handle):
17 | """
18 | """
19 | self._evtgrp = gdb.Value(handle).cast(EventGroupInspector.EvtGrpType)
20 |
21 | def GetTasksWaiting(self):
22 | """
23 | """
24 | taskListObj = self._evtgrp['xTasksWaitingForBits']
25 | taskList = ListInspector(taskListObj)
26 | return(taskList.GetElements(TaskInspector.TCBType))
27 |
28 |
29 | def GetEventBits(self):
30 | """ Get the Event Flag Bits
31 | @return L{gdb.Value} of EventBits_t
32 | """
33 | return(self._evtgrp['uxEventBits'])
34 |
--------------------------------------------------------------------------------
/src/FreeRTOS.py:
--------------------------------------------------------------------------------
1 | # File: FreeRTOS.py
2 | # Author: Carl Allendorph
3 | # Date: 05NOV2014
4 | #
5 | # Description:
6 | # This file contains some python code that utilizes the GDB API
7 | # to inspect information about the FreeRTOS internal state. The
8 | # idea is to provide the user with the ability to inspect information
9 | # about the tasks, queues, mutexs, etc.
10 | #
11 |
12 | import gdb
13 | import pprint
14 | from Types import StdTypes
15 | from List import ListInspector
16 | from GDBCommands import ShowHandleName, ShowRegistry, ShowList
17 | from GDBCommands import ShowQueueInfo
18 |
19 |
20 | class Scheduler:
21 |
22 | def __init__(self):
23 |
24 | self._blocked = ListInspector("xSuspendedTaskList")
25 | self._delayed1 = ListInspector("xDelayedTaskList1")
26 | self._delayed2 = ListInspector("xDelayedTaskList2")
27 | self._readyLists = []
28 | readyTasksListsStr = "pxReadyTasksLists"
29 | readyListsSym,methodType = gdb.lookup_symbol(readyTasksListsStr)
30 | if ( readyListsSym != None ):
31 | readyLists = readyListsSym.value()
32 | minIndex, maxIndex = readyLists.type.range()
33 | for i in range(minIndex, maxIndex+1):
34 | readyList = readyLists[i]
35 | FRReadyList = ListInspector( readyList )
36 | self._readyLists.append(FRReadyList)
37 | else:
38 | print("Failed to Find Symbol: %s" % readyTasksListsStr)
39 | raise ValueError("Invalid Symbol!")
40 |
41 | def ShowTaskList(self):
42 | self.PrintTableHeader()
43 | for i,rlist in enumerate(self._readyLists):
44 | if i == 0:
45 | items = rlist.GetElements( "TCB_t", 0 )
46 | else:
47 | items = rlist.GetElements( "TCB_t", 1 )
48 | if ( len(items) > 0 ):
49 | print("Ready List {%d}: Num Tasks: %d" % (i, len(items)))
50 | for tcb,val in items:
51 | self.PrintTaskFormatted(tcb)
52 |
53 | items = self._blocked.GetElements("TCB_t")
54 | print("Blocked List: Num Tasks: %d" % len(items))
55 | for tcb,val in items:
56 | self.PrintTaskFormatted(tcb)
57 |
58 | items = self._delayed1.GetElements("TCB_t")
59 | print("Delayed {1}: Num Tasks: %d" % len(items))
60 | for tcb,val in items:
61 | self.PrintTaskFormatted(tcb, val)
62 |
63 | items = self._delayed2.GetElements("TCB_t")
64 | print("Delayed {2}: Num Tasks: %d" % len(items))
65 | for tcb,val in items:
66 | self.PrintTaskFormatted(tcb, val)
67 |
68 |
69 | def PrintTableHeader(self):
70 | print("%16s %3s %4s" % ("Name", "PRI", "STCK"))
71 |
72 | def PrintTaskFormatted(self, task, itemVal = None):
73 | topStack=task['pxTopOfStack']
74 | stackBase = task['pxStack']
75 | highWater = topStack - stackBase
76 | taskName = task['pcTaskName'].string()
77 | taskPriority = task['uxPriority']
78 | if ( itemVal != None ):
79 | print("%16s %3s %4s %5s" % (taskName, taskPriority, highWater, itemVal))
80 | else:
81 | print("%16s %3s %4s" % (taskName, taskPriority, highWater))
82 |
83 |
84 | class ShowTaskList(gdb.Command):
85 | """ Generate a print out of the current tasks and their states.
86 | """
87 | def __init__(self):
88 | super(ShowTaskList, self).__init__(
89 | "show Task-List",
90 | gdb.COMMAND_SUPPORT
91 | )
92 |
93 | def invoke(self, arg, from_tty):
94 | sched = Scheduler()
95 | sched.ShowTaskList()
96 |
97 |
98 |
99 |
100 | ShowRegistry()
101 | ShowList()
102 | ShowTaskList()
103 | ShowHandleName()
104 | ShowQueueInfo()
105 |
106 |
--------------------------------------------------------------------------------
/src/GDBCommands.py:
--------------------------------------------------------------------------------
1 | # File: GDBCommands.py
2 | # Author: Carl Allendorph
3 | # Date: 05NOV2014
4 | #
5 | # Description:
6 | # This file contains the implementation of some custom
7 | # GDB commands for Inspecting the FreeRTOS state
8 |
9 |
10 | import gdb
11 | from List import ListInspector
12 | from Task import TaskInspector
13 | from HandleRegistry import HandleRegistry
14 | from Queue import QueueInspector, QueueMode
15 |
16 | class ShowQueueInfo(gdb.Command):
17 | """ Generate a print out of info about a particular
18 | set of queues.
19 | """
20 | def __init__(self):
21 | super(ShowQueueInfo, self).__init__(
22 | "show Queue-Info",
23 | gdb.COMMAND_SUPPORT
24 | )
25 |
26 | def invoke(self, arg, from_tty):
27 | argv = gdb.string_to_argv(arg)
28 |
29 | qTypes = []
30 | if( len(argv) > 0 ):
31 | for a in argv:
32 | try:
33 | qType = QueueMode.Map[a]
34 | qTypes.append(qType)
35 | except KeyError:
36 | print("Arg %s does not map to a Queue Type!" % a)
37 |
38 | reg = HandleRegistry()
39 | qToShow = []
40 | if ( len(qTypes) > 0 ):
41 | # We will only print info about queues
42 | for qType in qTypes:
43 | qObjs = reg.FilterBy(qType)
44 | qToShow.extend(qObjs)
45 | else:
46 | qToShow = reg.FilterBy(None)
47 |
48 | print("Num Queues: %d" % len(qToShow))
49 | print("%20s %4s %16s %16s" % ("NAME", "CNT", "SEND", "RECEIVE") )
50 | for q in qToShow:
51 | self.PrintQueueInfo(q)
52 |
53 | def PrintQueueInfo(self, q):
54 | """ Print Info about the Queue
55 | """
56 | sendList = q.GetTasksWaitingToSend()
57 | rxList = q.GetTasksWaitingToReceive()
58 |
59 | #print("TxLen: %d, RxLen: %d" % (len(sendList), len(rxList)))
60 |
61 | maxCount = max(len(sendList), len(rxList) )
62 | outputFmt = "%20s %4s %16s %16s"
63 | if ( maxCount == 0 ):
64 | print( outputFmt % (q.GetName(), q.GetQueueMessagesWaiting(), "", ""))
65 | else:
66 |
67 | for i in range(0, maxCount):
68 | txName = ""
69 | if ( i < len(sendList) ):
70 | tcbRef,val = sendList[i]
71 | tcb=TaskInspector(tcbRef)
72 | txName = tcb.GetName()
73 | rxName = ""
74 | if ( i < len(rxList) ):
75 | tcbRef,val = rxList[i]
76 | tcb = TaskInspector(tcbRef)
77 | rxName = tcb.GetName()
78 |
79 | if ( i == 0 ):
80 | print( outputFmt % (q.GetName(), q.GetQueueMessagesWaiting(), txName, rxName))
81 | else:
82 | print( outputFmt % ("", "", txName, rxName))
83 |
84 |
85 | class ShowHandleName(gdb.Command):
86 | """ Generate a print out of the handle by name
87 | """
88 | def __init__(self):
89 | super(ShowHandleName, self).__init__(
90 | "show Handle-Name",
91 | gdb.COMMAND_SUPPORT
92 | )
93 |
94 | def invoke(self, arg, from_tty):
95 | argv = gdb.string_to_argv(arg)
96 | if ( len(argv) != 1 ):
97 | print("Invalid Argument: Requires one handle arg")
98 | handle = int( argv[0], 0)
99 | reg = HandleRegistry()
100 | name = reg.GetName(handle)
101 | print("Handle 0x%08x: %s" % (handle, name))
102 |
103 | class ShowRegistry(gdb.Command):
104 | """ Generate a print out of the queue handle registry
105 | """
106 | def __init__(self):
107 | super(ShowRegistry, self).__init__(
108 | "show Handle-Registry",
109 | gdb.COMMAND_SUPPORT
110 | )
111 |
112 | def invoke(self, arg, from_tty):
113 | reg = HandleRegistry()
114 | reg.PrintRegistry()
115 |
116 |
117 | class ShowList(gdb.Command):
118 | """ Generate a print out of the elements in a list
119 | passed to this command. User must pass a symbol that
120 | will be looked up.
121 | """
122 |
123 | def __init__(self):
124 | super(ShowList, self).__init__(
125 | "show List-Handle",
126 | gdb.COMMAND_SUPPORT,
127 | gdb.COMPLETE_SYMBOL
128 | )
129 |
130 | def invoke(self, arg, from_tty):
131 | argv = gdb.string_to_argv(arg)
132 |
133 | CastTypeStr = None
134 | if ( len(argv) > 0):
135 | symbolArg = argv[0]
136 |
137 | if ( len(argv) > 1 ):
138 | CastTypeStr = argv[1]
139 |
140 | listVal = ListInspector(symbolArg)
141 |
142 | elems = listVal.GetElements( CastTypeStr )
143 |
144 | for elem in elems :
145 | print("Elem: %s" % str(elem))
146 |
--------------------------------------------------------------------------------
/src/HandleRegistry.py:
--------------------------------------------------------------------------------
1 | # File: HandleRegistry.py
2 | # Author: Carl Allendorph
3 | # Date: 06NOV2014
4 | #
5 | # Description:
6 | # THis file contains the implementation of a class for accessing the
7 | # handle registry. This contains a mapping of queue handles to
8 | # strings for labeling purposes.
9 |
10 | import gdb
11 | from Types import StdTypes
12 | from Queue import QueueInspector, QueueMode
13 |
14 | class HandleRegistry:
15 | """ The FreeRTOS system can be configured with a table that
16 | associates a name with a QueueHandle_t.
17 | This class can be used to access this table and
18 | label queue/mutex/semaphore/event groups
19 | """
20 | def __init__(self, regSymbol = "xQueueRegistry"):
21 | symbol, methodObj = gdb.lookup_symbol(regSymbol)
22 | self._registry = symbol.value()
23 | self._minIndex = 0
24 | self._maxIndex = 0
25 | self._minIndex, self._maxIndex = self._registry.type.range()
26 |
27 | def GetName(self, handle):
28 | """ Find the string name associated with a queue
29 | handle if it exists in the registry
30 | """
31 | for i in range(self._minIndex, self._maxIndex):
32 | elem = self._registry[i]
33 | h = elem['xHandle']
34 | val = h.cast(StdTypes.uint32_t)
35 | if ( handle == val ):
36 | print("Found Entry for: %x" % handle)
37 | name = elem['pcQueueName'].string()
38 | return(name)
39 |
40 | def PrintRegistry(self):
41 | for i in range(self._minIndex, self._maxIndex):
42 | elem = self._registry[i]
43 | h = elem['xHandle']
44 | if ( h != 0 ):
45 | name = elem['pcQueueName'].string()
46 | print("%d: %3s %16s" % (i, h, name))
47 |
48 | def FilterBy(self, qMode):
49 |
50 | """ Retrieve a List of Mutex Queue Handles
51 | """
52 | resp = []
53 | for i in range(self._minIndex, self._maxIndex):
54 | elem = self._registry[i]
55 | h = elem['xHandle']
56 | if ( h != 0 ):
57 | name = elem['pcQueueName'].string()
58 | q = QueueInspector(h)
59 | q.SetName(name)
60 | if ( qMode != None ):
61 | qType = q.GetQueueType()
62 | if ( qType != None ):
63 | if ( qType == qMode ):
64 | resp.append(q)
65 |
66 | else:
67 | print("qType == None")
68 | else:
69 | resp.append(q)
70 |
71 | return(resp)
72 |
73 | def GetMutexes(self):
74 | """ Retrieve all the Mutex Objects in the Handle Registry
75 | """
76 | return( self.FilterBy( QueueMode.MUTEX) )
77 |
78 | def GetSemaphores(self):
79 | """ Retrieve all the Semaphore Objects in the Handle Registry
80 | """
81 | return( self.FilterBy( QueueMode.BINARY) )
82 |
83 |
84 | def GetQueues(self):
85 | """ Retrieve all the Queue Objects in the Handle Registry
86 | """
87 | return( self.FilterBy( QueueMode.QUEUE) )
88 |
89 |
90 |
--------------------------------------------------------------------------------
/src/List.py:
--------------------------------------------------------------------------------
1 | # File: List.py
2 | # Author: Carl Allendorph
3 | # Date: 05NOV2014
4 | #
5 | # Description:
6 | # This file contains the class for inspecting
7 | # a FreeRTOS List Object
8 | #
9 |
10 |
11 | import gdb
12 |
13 | from Types import StdTypes
14 |
15 | class ListInspector:
16 | """ FreeRTOS List Inspector Object
17 | """
18 |
19 | ListType = gdb.lookup_type("List_t")
20 |
21 | def __init__(self, handle ):
22 | """
23 | """
24 | self._list = None
25 | # print("List: Handle: %s" % handle)
26 | self.Assign(handle)
27 |
28 | def Assign(self, listObj):
29 | try:
30 | if ( listObj.type == ListInspector.ListType ):
31 | self._list = listObj
32 | return
33 | else:
34 | raise TypeError("Invalid List Object Type!")
35 | except Exception as exc:
36 | #print(" Failed to assign from List object: %s" % str(exc))
37 | pass
38 |
39 | symbol, methodObj = gdb.lookup_symbol(listObj)
40 | if ( symbol != None ):
41 | self._list = symbol.value()
42 | else:
43 | addrInt = int(listObj, 0)
44 | listObjPtr = gdb.Value(addrInt).cast(ListInspector.ListType.pointer())
45 | self._list = listObjPtr.dereference()
46 |
47 |
48 |
49 | def GetElements(self, CastTypeStr = None, startElem = 1 ):
50 | """ Get the Elements of the list as an array of
51 | gdb.Value type objects.
52 | @param CastTypeStr string name of the type of object that
53 | we will cast the void *pvOwner elements of the list to.
54 | User can also pass a L{gdb.Type} object as the type
55 | If None, we will simply cast to uint32_t and print these
56 | as hex values.
57 | @param startElem This is a flag to indicate whether
58 | we will start getting elements starting at 0 or 1. Note
59 | that this is to deal with some non-consistent behavior
60 | of some of the TCB Task lists.
61 | """
62 | if ( self._list != None ):
63 |
64 | CastType = None
65 | if ( CastTypeStr != None):
66 | if( type(CastTypeStr) == str ):
67 | try:
68 | CastType = gdb.lookup_type(CastTypeStr).pointer()
69 | except:
70 | print("Failed to find type: %s" % CastTypeStr)
71 | elif ( type(CastTypeStr) == gdb.Type):
72 | CastType = CastTypeStr.pointer()
73 |
74 |
75 | resp = []
76 | numElems = self._list['uxNumberOfItems']
77 | #print("List Elements: %d" % numElems)
78 | index = self._list['pxIndex']
79 |
80 | if ( numElems > 0 and numElems < 200 ):
81 |
82 | if ( startElem == 0 ):
83 | curr = index
84 | else:
85 | curr = index['pxPrevious']
86 |
87 | for i in range(0, numElems):
88 | owner = curr['pvOwner']
89 |
90 |
91 | ownerObj = None
92 | if ( CastType != None ):
93 | castObjPtr = owner.cast(CastType)
94 | castObj = castObjPtr.dereference()
95 | ownerObj = castObj
96 | else:
97 | ownerUInt = owner.cast(StdTypes.uint32_t)
98 | ownerObj = ownerUInt
99 |
100 | itemVal = curr['xItemValue']
101 | resp.append( (ownerObj, itemVal.cast(StdTypes.uint32_t)) )
102 |
103 | curr = curr['pxPrevious']
104 |
105 | return(resp)
106 |
107 | else:
108 | raise ValueError("Invalid List Object - Possibly Failed to Initialize!")
109 |
110 |
--------------------------------------------------------------------------------
/src/Queue.py:
--------------------------------------------------------------------------------
1 | # File: Queue.py
2 | # Author: Carl Allendorph
3 | # Date: 05NOV2014
4 | #
5 | # Description:
6 | # This file contains the implementation of a Queue Inspector
7 | # class.
8 | #
9 |
10 | import gdb
11 | from List import ListInspector
12 | from Task import TaskInspector
13 |
14 |
15 | class QueueMode:
16 | QUEUE = 0
17 | MUTEX = 1
18 | COUNTING = 2
19 | BINARY = 3
20 | RECURSIVE = 4
21 |
22 | Map = None
23 |
24 | @staticmethod
25 | def IsValid(qType):
26 | if ( qType == QueueMode.QUEUE or
27 | qType == QueueMode.MUTEX or
28 | qType == QueueMode.COUNTING or
29 | qType == QueueMode.BINARY or
30 | qType == QueueMode.RECURSIVE ):
31 | return(True)
32 | else:
33 | return(False)
34 |
35 | QueueMap = {
36 | "mutex" : QueueMode.MUTEX,
37 | "queue" : QueueMode.QUEUE,
38 | "semaphore" : QueueMode.BINARY,
39 | "counting" : QueueMode.COUNTING,
40 | "recursive" : QueueMode.RECURSIVE,
41 | }
42 |
43 | QueueMode.Map = QueueMap
44 |
45 |
46 |
47 | class QueueInspector:
48 |
49 | QueueType = gdb.lookup_type("Queue_t")
50 |
51 | def __init__(self, handle):
52 | """
53 | """
54 | # print("Queue: Handle: %s" % handle)
55 | self.name = None
56 | queueObjPtr = None
57 | if ( type(handle) == gdb.Value ):
58 | queueObjPtr = handle.cast(QueueInspector.QueueType.pointer())
59 | self._queue = queueObjPtr.dereference()
60 | else:
61 | queueObjPtr = gdb.Value(handle).cast(QueueInspector.QueueType.pointer())
62 | self._queue = queueObjPtr.dereference()
63 |
64 |
65 | def GetName(self):
66 | return(self.name)
67 |
68 | def SetName(self, name):
69 | self.name = name
70 |
71 | def GetTasksWaitingToSend(self):
72 | """ Retrieve a list of gdb.Value objects of type
73 | TCB that are the tasks that are currently waiting to
74 | send data on this queue object.
75 | """
76 | sendList = ListInspector(self._queue['xTasksWaitingToSend'])
77 |
78 | return( sendList.GetElements( TaskInspector.TCBType ))
79 |
80 | def GetTasksWaitingToReceive(self):
81 | """ Retrieve a list of gdb.Value objects of Type
82 | TCB that are the tasks that are currently waiting to
83 | receive data on this queue object.
84 | """
85 | rxList = ListInspector( self._queue['xTasksWaitingToReceive'] )
86 | return( rxList.GetElements( TaskInspector.TCBType) )
87 |
88 | def GetQueueMessagesWaiting(self):
89 | """ Return the number of messages waiting as a
90 | L{gdb.Value} object
91 | """
92 | return( self._queue['uxMessagesWaiting'] )
93 |
94 | def GetQueueType(self):
95 | """ Return the Type of the Queue as a enumerated number
96 |
97 | """
98 | try:
99 | qType = self._queue['ucQueueType']
100 | if ( QueueMode.IsValid(int(qType)) ):
101 | return(qType)
102 | else:
103 | raise ValueError("Invalid Queue Type In Queue Object! Are you sure this is a Queue Handle?")
104 |
105 | except Exception as exc:
106 | # If the TRACE functionality of the RTOS is not enabled,
107 | # then the queue type will not be availabe in the queue
108 | # handle - so we return None
109 | print("Failed to get Type: %s" % str(exc))
110 | return(None)
111 |
112 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/src/Task.py:
--------------------------------------------------------------------------------
1 | # File: Task.py
2 | # Author: Carl Allendorph
3 | # Date: 05NOV2014
4 | #
5 | # Description:
6 | # This file contains the implementation of a class to use for
7 | # inspecting the state of a FreeRTOS Task in GDB
8 | #
9 |
10 | import gdb
11 |
12 | class TaskInspector:
13 |
14 | TCBType = gdb.lookup_type("TCB_t")
15 |
16 | def __init__(self, handle):
17 | self._tcb = None
18 | #print("Task: Pass Handle: %s" % str(handle))
19 |
20 | try:
21 | if ( handle.type == TaskInspector.TCBType ):
22 | self._tcb = handle
23 | return
24 | else:
25 | print("Handle Type: %s" % str(handle.type))
26 |
27 | except AttributeError as aexc:
28 | print("Attribute Error: %s" % str(aexc))
29 | pass
30 | except Exception as exc:
31 | print("Error Initializing Task Inspector: %s" % str(exc))
32 | raise
33 |
34 | try:
35 | tcbPtr = gdb.Value(handle).cast(TaskInspector.TCBType.pointer())
36 | self._tcb = tcbPtr.dereference()
37 | return
38 | except Exception as exc:
39 | print("Failed to convert Handle Pointer: %s" % str(handle))
40 |
41 | self._tcb = handle
42 |
43 |
44 |
45 | def GetName(self):
46 | if ( self._tcb != None):
47 | return( self._tcb['pcTaskName'].string() )
48 | else:
49 | raise ValueError("Invalid TCB")
50 |
51 | def GetPriority(self):
52 | if ( self._tcb != None ):
53 | return ( self._tcb['uxPriority'] )
54 | else:
55 | raise ValueError("Invalid TCB")
56 |
57 | def GetStackMargin(self):
58 | if ( self._tcb != None ):
59 | topStack=self._tcb['pxTopOfStack']
60 | stackBase = self._tcb['pxStack']
61 | highWater = topStack - stackBase
62 | return(highWater)
63 | else:
64 | raise ValueError("Invalid TCB")
65 |
66 |
67 |
--------------------------------------------------------------------------------
/src/Types.py:
--------------------------------------------------------------------------------
1 | # File: Types.py
2 | # Author: Carl Allendorph
3 | # Date: 05NOV2014
4 | #
5 | # Description:
6 | # This file contains the implementation of some
7 | # standard types
8 |
9 | import gdb
10 |
11 | class StdTypes:
12 | uint32_t = gdb.lookup_type("uint32_t")
13 | uint16_t = gdb.lookup_type("uint16_t")
14 |
--------------------------------------------------------------------------------
/src/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/autolycus/FreeRTOS-GDB/f6aaa90c565773812e6ffa9e752c4ecb0fbe5fe8/src/__init__.py
--------------------------------------------------------------------------------