Remote debugging:
Connecting to remote target
a) (gdb) target remote /dev/ttyb # serial-device
b) (gdb) target remote host:port
c) (gdb) target remote protocol:host:port
d) (gdb) target remote | middleman-command # gdb talks to a middleman command
Transfer files:
remote put hostfile targetfile
remote get targetfile hostfile
remote delete targetfile
(gdb) load filename # this command is used instead of 'run' in case of remote debugging
(gdb) break
(gdb) step
(gdb) continue
(gdb) detach
(gdb) disconnect
a) Remote gdbserver on target with gdb on host (Need O.S. for this):
target> gdbserver /dev/com1 emacs foo.txt
target> gdbserver host:2345 emacs foo.txt
target> gdbserver --attach /dev/com1 pid
# Run a wrapper for the debugee program on the target-side
target> gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
#Connect to the target gdbserver from my host gdb
$ gdb myprogram
(gdb) target remote myhost:9999
0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
(gdb) b main
(gdb) continue
# Send commands to gdbserver using the monitor command
monitor help # List the available monitor commands.
monitor set debug 0 | 1 # Disable or enable general debugging messages
monitor set remote-debug 0|1 # Disable or enable debugging messages of the remote protocol
monitor exit
See Also: Remote Configuration
More in-depth internal look at Remote Protocol
b) Remote Stub: Used on Embedded devices without an O.S.
Blogs:
1) http://blog.flameeyes.eu/2010/02/20/remote-debugging-with-gdb-part-2-gdb
2) http://www.gentoo.org/proj/en/qa/backtraces.xml
Sunday, November 7, 2010
Debugging Multiple Processes/Threads with GDB
Debugging multiple inferiors and programs
Gdb allows you to debug multiple programs at once without exiting the process you're currently running.
Gdb uses an inferior as a handle for a process. An inferior is attachable/detachable from a process
info inferiors # display list of current inferiors.
inferior infno # make inferior number infno the current inferior
Loading multiple inferiors:
2) clone-inferior [ -copies n ] [ infno ] # n defaults to 1 and infno defaults to current inferior number
Ending the inferiority complex:
remove-inferior infno # Remove the empty inferior Note: Can't remove an inferior with a running assoc. process.
detach-inferior infno # detaches from an inferior from assoc. process
kill-inferiror infno # kills the process attached to the inferior. It can be removed or re-attached to some process.
Debugging Multi-threaded Programs:
info threads # displays thread info - thread number, thread-id, stack frame summary
thread threadno # make threadno as active current thread and shows stack frame summary
Starting and Stopping Multi-thread Programs
2 modes of debugging:
1) All stop mode: aka 3 musketeers mode i.e. "All-for-one, One-for-all"
2) Non-stop mode:
set target-async on|off # Switch asynchronous mode.
show target-async # Show the current target-async setting.
interrupt # suspend execution of the running program (whole process in all-stop, current thread in non-stop modes)
interrupt -a # stop the whole program in non-stop mode
Gdb allows you to debug multiple programs at once without exiting the process you're currently running.
Gdb uses an inferior as a handle for a process. An inferior is attachable/detachable from a process
info inferiors # display list of current inferiors.
(gdb) info inferiors Num Description Executable 2 process 2307 hello * 1 process 3401 goodbyeSwitch to another inferior:
inferior infno # make inferior number infno the current inferior
Loading multiple inferiors:
1) add-inferior [ -copies n ] [ -exec executable ] # n defaults to 1 and optional exec gives an empty inferior2) clone-inferior [ -copies n ] [ infno ] # n defaults to 1 and infno defaults to current inferior number
Ending the inferiority complex:
remove-inferior infno # Remove the empty inferior Note: Can't remove an inferior with a running assoc. process.
detach-inferior infno # detaches from an inferior from assoc. process
kill-inferiror infno # kills the process attached to the inferior. It can be removed or re-attached to some process.
Debugging Multi-threaded Programs:
info threads # displays thread info - thread number, thread-id, stack frame summary
thread threadno # make threadno as active current thread and shows stack frame summary
Starting and Stopping Multi-thread Programs
2 modes of debugging:
1) All stop mode: aka 3 musketeers mode i.e. "All-for-one, One-for-all"
2) Non-stop mode:
set target-async on|off # Switch asynchronous mode.
show target-async # Show the current target-async setting.
interrupt # suspend execution of the running program (whole process in all-stop, current thread in non-stop modes)
interrupt -a # stop the whole program in non-stop mode
Saturday, October 30, 2010
The Pyramid of Knowledge
Knowledge can be thought of as a Pyramid of Information, like the predator-prey biological pyramid or energy distribution in an ecosystem.
Building the Knowledge Pyramid is like a "Fox and Hounds Paper Chase" so that the Walk-The-Long-Road on the Information Trail/Path becomes much easier.
First need to categorize learning resources into 3 levels:
1) Top-Down: Solution Space - What problems does this technology address and solve?
2) Middle-Up/Down: Module level concepts like Manager code e.g. Virtual Filesystem Cache Manager, Storage Manager
3) Bottom-Up:
Search for Short-Intros materials like ppts, podcasts, pdfs, research papers, articles, blogs, videos, mindmaps, TOC
Find the Gurus in the trade and their JourneyMan followers
Subscribe to RSS Feeds to blogs by them
1) JourneyMen in the domain like Yeshawant Kanetkar who explain things well to Apprentices (WalkInThePark Pattern)
2) MasterCraftsMen in the domain like Stroustrup, Richter, Butenhof (WalkInTheForest Pattern)
0) Blogs, articles or PPTs doing a system walk-through relating how various things and flows through the system
like "Gusatvo Duartes blogs on Operating Systems"
1) General books to get a feel for the domain and common constraints, solutions, patterns and principles
like "Operating System Principles", "Distributed Systems: Principles and Paradigms"
2) Applied Books using APIs, Frameworks
like"Linux System Programming", "Windows Application Programming by Richter"
3) System/Sub-System Level books describing internals of APIs, Frameworks
like "Understanding the Linux Kernel", "MFC Internals"
Categorizing Method Applied to Information Trail:
Follow most referred book/white-paper trail in collections like Bibliographies, Appendices, References etc.
This method works on any of the above 3 levels,
Example:
Get generic Distributed domain book from amazon and follow Up/Down to higher/lower levels of Pyramid.
"Distributed Systems: Principles and Paradigms" -> "C++ Network Programming" ->
a) POSA2 (Basic Distributed Patterns)-> POSA3 (Resource Mgmt Patterns) - (Design Level Classics)
b) Operating System -> "Operating System Principles" by Galvin -> "Understanding theLinux Kernel" by Bovet and Cesati
c) Module Level Concepts -> Caching Virtual FileSystems, Remoting Patterns -> Research Papers -> Classic Books referring to the Research Papers
d) Networking -> "Programming the Sockets API" by Stevens -> ... -> "Linux Network Internals" (Implementation Level Classics)
On a Related Note:
A Concept Map can very nicely simulate such a Tree of knowledge.
Hmmm.... kind of like the way WikiMindMap hierarchically orgranises a Wikipedia article into a tree structure. So we can do the following to convert a wiki/webpage into a concept map:
1) Use WikiMindMap to convert wikipedia article into a Freemind MindMap and export it as a .mm file
2) Use XMind to convert the .mm file into an XMind Concept Map which is shareable and editable with friends.
Building the Knowledge Pyramid is like a "Fox and Hounds Paper Chase" so that the Walk-The-Long-Road on the Information Trail/Path becomes much easier.
First need to categorize learning resources into 3 levels:
1) Top-Down: Solution Space - What problems does this technology address and solve?
2) Middle-Up/Down: Module level concepts like Manager code e.g. Virtual Filesystem Cache Manager, Storage Manager
3) Bottom-Up:
Search for Short-Intros materials like ppts, podcasts, pdfs, research papers, articles, blogs, videos, mindmaps, TOC
Find the Gurus in the trade and their JourneyMan followers
Subscribe to RSS Feeds to blogs by them
1) JourneyMen in the domain like Yeshawant Kanetkar who explain things well to Apprentices (WalkInThePark Pattern)
2) MasterCraftsMen in the domain like Stroustrup, Richter, Butenhof (WalkInTheForest Pattern)
0) Blogs, articles or PPTs doing a system walk-through relating how various things and flows through the system
like "Gusatvo Duartes blogs on Operating Systems"
1) General books to get a feel for the domain and common constraints, solutions, patterns and principles
like "Operating System Principles", "Distributed Systems: Principles and Paradigms"
2) Applied Books using APIs, Frameworks
like"Linux System Programming", "Windows Application Programming by Richter"
3) System/Sub-System Level books describing internals of APIs, Frameworks
like "Understanding the Linux Kernel", "MFC Internals"
Categorizing Method Applied to Information Trail:
Follow most referred book/white-paper trail in collections like Bibliographies, Appendices, References etc.
This method works on any of the above 3 levels,
Example:
Get generic Distributed domain book from amazon and follow Up/Down to higher/lower levels of Pyramid.
"Distributed Systems: Principles and Paradigms" -> "C++ Network Programming" ->
a) POSA2 (Basic Distributed Patterns)-> POSA3 (Resource Mgmt Patterns) - (Design Level Classics)
b) Operating System -> "Operating System Principles" by Galvin -> "Understanding theLinux Kernel" by Bovet and Cesati
c) Module Level Concepts -> Caching Virtual FileSystems, Remoting Patterns -> Research Papers -> Classic Books referring to the Research Papers
d) Networking -> "Programming the Sockets API" by Stevens -> ... -> "Linux Network Internals" (Implementation Level Classics)
On a Related Note:
A Concept Map can very nicely simulate such a Tree of knowledge.
Hmmm.... kind of like the way WikiMindMap hierarchically orgranises a Wikipedia article into a tree structure. So we can do the following to convert a wiki/webpage into a concept map:
1) Use WikiMindMap to convert wikipedia article into a Freemind MindMap and export it as a .mm file
2) Use XMind to convert the .mm file into an XMind Concept Map which is shareable and editable with friends.
Howto Learn in Small Chunks - (Bite Sized Learning)
Many of the curious and interested people always end up saying at one time or another....
"I've really wanted to learn more BUT I can't seem to find the time for it...."
What happens to our time, after all as someone said "God gave each one of us 24 hours".
So how is that some people seem to make so much more use of them than others?
Apart from the solid block of time allocated for our salary-paying masters what's left of them?
Waiting in queues for doctors, meetings to start, buses to show up.... these are the places we lose our free-time 24 hours.
a) The main problem is these time-chunks are fragmented i.e. the free chunks occur in-between major tasks. We need some method to connect these small fragments together
b) Mostly these free-time chunks are too small to do any significant work.
c) Sometimes we cannot predict when we'll get these free minutes/hours. So we tend to browse stuff and use up these fragments of time.
But there is a way that we can make full use of these time-chunks if we learn how to
a) Learn in small chunks by finding bite-sized activities.
b) Actively Record-What-You-Learn so that you can continue where you left off last time. This way the task switching overhead is minimized as you save your work every few minutes - kinda like saving that important file so you don't lose all your work when the computer hangs.
1) Subscribe to RSS Feeds to blogs by Gurus in the trade and their followers (WalkInThePark, WalkInTheForest Patterns)
2) Browse constantly using a phone/iPad to browse the net on idle time-chunks like waiting for the bus, doctor, queue etc.
3) Keep a book handy for power-cuts, reading on bus etc. (Make sure that it's small enough and has big letters for easy reading). StudyTheClassics to avoid wasting time on useless stuff. Amazon ratings may not be the best guide at all times. A classic is normally referenced by many books even the time-waste ones. Utilize the bibliography at the end of most books.
4) Learn Research-Techniques like Skimming, SpeedReading, Mindmapping on a book for quick outline of the book to be added in the book review.
5) Capture the essence of what you understood by taking notes a book for quick reference later.
Use the book fully -
1) Annotate the TOC with educated guesses and already known-facts gathered from Short-Intros. Peek into topics which you can't explain well to yourself or to refresh/cross-check your memory.
2) Categorize the bibliography into ShortIntros, Mid-Stuff, Adv-Stuff to build up your Knowledge Pyramid
3) Keep incrementing your blog on the topic with all resources - links, notes, thoughts, questions.
4) Keep Reviewing your blog to reduce/add TODOs:
correct grammatical mistakes,
add further links for later annotation,
cleanup and reorganize information,
re-view the gathered information with a fresh eye,
simplify, clarify, generalize, specify, elaborate, concise information,
split of a huge post into different blog posts
(each post should not be more than 2 PageDowns for the reader)
5) IMPORTANT: Blog should not be a place where information goes to die but a place where it comes alive.
With each review and update it should spawn a new generation of Rise-From-The-Ashes-Phoenixes.
6) You'll be surprised to see how much you can achieve in small bites spread across time.
See Also:
How to Read A Book And Why (from bookshelved wiki)
"I've really wanted to learn more BUT I can't seem to find the time for it...."
What happens to our time, after all as someone said "God gave each one of us 24 hours".
So how is that some people seem to make so much more use of them than others?
Apart from the solid block of time allocated for our salary-paying masters what's left of them?
Waiting in queues for doctors, meetings to start, buses to show up.... these are the places we lose our free-time 24 hours.
a) The main problem is these time-chunks are fragmented i.e. the free chunks occur in-between major tasks. We need some method to connect these small fragments together
b) Mostly these free-time chunks are too small to do any significant work.
c) Sometimes we cannot predict when we'll get these free minutes/hours. So we tend to browse stuff and use up these fragments of time.
But there is a way that we can make full use of these time-chunks if we learn how to
a) Learn in small chunks by finding bite-sized activities.
b) Actively Record-What-You-Learn so that you can continue where you left off last time. This way the task switching overhead is minimized as you save your work every few minutes - kinda like saving that important file so you don't lose all your work when the computer hangs.
1) Subscribe to RSS Feeds to blogs by Gurus in the trade and their followers (WalkInThePark, WalkInTheForest Patterns)
2) Browse constantly using a phone/iPad to browse the net on idle time-chunks like waiting for the bus, doctor, queue etc.
3) Keep a book handy for power-cuts, reading on bus etc. (Make sure that it's small enough and has big letters for easy reading). StudyTheClassics to avoid wasting time on useless stuff. Amazon ratings may not be the best guide at all times. A classic is normally referenced by many books even the time-waste ones. Utilize the bibliography at the end of most books.
4) Learn Research-Techniques like Skimming, SpeedReading, Mindmapping on a book for quick outline of the book to be added in the book review.
5) Capture the essence of what you understood by taking notes a book for quick reference later.
Use the book fully -
1) Annotate the TOC with educated guesses and already known-facts gathered from Short-Intros. Peek into topics which you can't explain well to yourself or to refresh/cross-check your memory.
2) Categorize the bibliography into ShortIntros, Mid-Stuff, Adv-Stuff to build up your Knowledge Pyramid
3) Keep incrementing your blog on the topic with all resources - links, notes, thoughts, questions.
4) Keep Reviewing your blog to reduce/add TODOs:
correct grammatical mistakes,
add further links for later annotation,
cleanup and reorganize information,
re-view the gathered information with a fresh eye,
simplify, clarify, generalize, specify, elaborate, concise information,
split of a huge post into different blog posts
(each post should not be more than 2 PageDowns for the reader)
5) IMPORTANT: Blog should not be a place where information goes to die but a place where it comes alive.
With each review and update it should spawn a new generation of Rise-From-The-Ashes-Phoenixes.
6) You'll be surprised to see how much you can achieve in small bites spread across time.
See Also:
How to Read A Book And Why (from bookshelved wiki)
Useful Sections of a Syntopic Learning Post
0) Add a TODO section at the top for quickly scanning pending actions on the blog
1) Build the Knowledge Pyramid one link at a time.
2) Add Short-Intros: ppts, podcasts, pdfs, research papers, articles, blogs, videos, mindmaps, TOC, tutorials, sample-code, howtos,
3) Add Mid-Stuff: guides, idioms, best-practises, FAQs, Gotchas, traps-and-pitfalls
4) Add Adv-Stuff: Design-level stuff, Patterns etc.
1) Build the Knowledge Pyramid one link at a time.
2) Add Short-Intros: ppts, podcasts, pdfs, research papers, articles, blogs, videos, mindmaps, TOC, tutorials, sample-code, howtos,
3) Add Mid-Stuff: guides, idioms, best-practises, FAQs, Gotchas, traps-and-pitfalls
4) Add Adv-Stuff: Design-level stuff, Patterns etc.
Subscribe to:
Posts (Atom)
