mikeash.com pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html commentshttp://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsmikeash.com Recent CommentsThu, 28 Mar 2024 21:48:30 GMTPyRSS2Gen-1.0.0http://blogs.law.harvard.edu/tech/rssHugo Rumens - 2012-08-23 13:46:10http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsThis article is a great resource. <br /> <br />One thing I would add is I've found that putting in a cast for the return type when doing a print-object is not always necessary, e.g. with a method returning a string, both of these work: <br /> <br /><code> <br />(gdb) po [someObject someMethodReturningNSString] <br />or <br />(gdb) po (NSString *) [someObject someMethodReturningNSString] <br /></code> <br /> <br />However, if trying to call a method that takes an argument: <br /> <br /><code> <br />- (NSString *)someMethod:(NSDictionary *)dict; <br /></code> <br /> <br />calling <br /> <br /><code> <br />(gdb) po (NSString *) [someObject someMethod:[NSDictionary dictionary]] <br /></code> <br /> <br />gives you the infamous (even though there is a return type cast) <br /> <br />Unable to call function "objc_msgSend" at 0x7fff84f100f4: no return type information available. <br /> <br />You have to cast the argument as well: <br /> <br /><code> <br />(gdb) po (NSString *) [someObject someMethod:(NSDictionary *) [NSDictionary dictionary]] <br /></code> <br /> <br />I've also found you can't pass nil - this won't work: <br /> <br /><code> <br />(gdb) po (NSString *) [someObject someMethod:(NSDictionary *) nil] <br /></code>1b02944177472e39d58afcdae4f3ddb2Thu, 23 Aug 2012 13:46:10 GMTmikeash - 2011-07-15 01:13:12http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsVery cool, thanks!ebfd884fad7d71e0df88892ed91fc364Fri, 15 Jul 2011 01:13:12 GMTSagyuwara - 2011-07-14 02:27:56http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsI'm sorry for not responding sooner. <br />The link is <a href="http://www.cocoachina.com/bbs/read.php?tid-66525.html">http://www.cocoachina.com/bbs/read.php?tid-66525.html</a>. <br />Thanks again.94576c68c7acc99cf44c1da3f4f53cd4Thu, 14 Jul 2011 02:27:56 GMTmikeash - 2011-07-08 14:20:49http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsPlease feel free to post translations, just provide attribution and a link to the original. If you do this, I'd love to see a link to the translation even if I can't understand it!623e1e244dfe3427ec413182eb181febFri, 08 Jul 2011 14:20:49 GMTSagyuwara - 2011-07-08 08:01:56http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsVery simple and clear article. Thanks a lot. <br /> <br />Is it allowed to translate and post it on other forums?6327c722f9d4a11fb06dbf737bcf5b99Fri, 08 Jul 2011 08:01:56 GMTBen - 2011-07-06 19:44:24http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsAwesome article, interesting to see the things it can do with Objective-C. <br /> <br />Don't forget about the <code>step</code> and <code>finish</code> commands (abbreviated <code>s</code> and <code>f</code>). They let you step into and out of the current function and are very useful for navigating shallow stacks when debugging in a localized area.3f58be4cc63923f6471c262282532112Wed, 06 Jul 2011 19:44:24 GMTMohamed - 2011-06-29 20:56:31http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsVery nice tutorial. Very nice.bff2540fec63612c9e390107af80dbd5Wed, 29 Jun 2011 20:56:31 GMTSefTarbell - 2011-06-24 14:40:07http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsExcellent article, I have found myself struggling with anything in gdb outside the basic p &amp; po. This gave me a bunch of new things to try!babac638e4ee045d4b77ede841d967ffFri, 24 Jun 2011 14:40:07 GMTssp - 2011-06-21 06:09:13http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsThanks for the examples, Mike.dc9cfb7ca764482674ffaf8aefed10f5Tue, 21 Jun 2011 06:09:13 GMTmikeash - 2011-06-21 01:28:12http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsXcode does allow you to access nearly everything gdb can do, but there are a couple of gotchas. <br /> <br />One is that if you ever need to run gdb as root, say, to debug a process that runs as root, Xcode gets really inconvenient. <br /> <br />The other is that Xcode's GUI wrapper is buggy. I've had bugs in my code which completely destroyed Xcode's debugger due to weird data propagating up to the UI layer, but which command-line gdb handled fine.9280a8846867e65f067053376832871eTue, 21 Jun 2011 01:28:12 GMTSSteve - 2011-06-20 22:00:15http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsOh, sorry. I didn't notice the <code>@</code> got removed. I thought that line of code was just a placeholder. I obviously need to try harder to read bugs. :-)d5421809cedf8de4299acd5270ecd82eMon, 20 Jun 2011 22:00:15 GMTssp - 2011-06-20 21:38:10http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsVery nice writeup, thanks a lot! <br /> <br />For curiosity's sake: care to give an example of something that doesn't work when using gdb from Xcode? I had the impression that – among the GUI-stuff – Xcode just offers a gdb console as well.a249e54545aec6a8a71d9a9f590aada0Mon, 20 Jun 2011 21:38:10 GMTmikeash - 2011-06-20 21:31:22http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsIf you mean the very first one under Getting Started, that's intended to be a working program. The bugs come later. It was tough to come up with realistic bugs, though....cf8f288c10d761b043ed3b8036cc0ba2Mon, 20 Jun 2011 21:31:22 GMTSSteve - 2011-06-20 21:03:09http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsThe first code example shouldn't have the <code>@</code> before <code>"Hello World!"</code>. You obviously need to try harder to write bugs. :-)db03f6903a76626b837c44e9991e4398Mon, 20 Jun 2011 21:03:09 GMTPádraig Brady - 2011-06-20 11:56:01http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsMy most common use of gdb is with: gdb -tui -args .... <br />That starts a curses interface which you can see in action here: <br /><a href="http://www.pixelbeat.org/programming/debugger/">http://www.pixelbeat.org/programming/debugger/</a>1e3dd1c6956756cac0ff991cadd2b81eMon, 20 Jun 2011 11:56:01 GMTmikeash - 2011-06-20 01:43:08http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsRunning gdb separately is really only for when you can't, or at least don't want to, get Xcode involved at all. For example, debugging processes belonging to a different user, where you need to run the debugger as root, or getting gdb attached to some process for which there's no corresponding Xcode project, or unfortunate situations where you trigger bugs in Xcode which cause it to crash or otherwise fail at debugging. It's a nice skill to have because of that, but it doesn't really help except for specific situations.0e54b081e11c36864a6133403315d47aMon, 20 Jun 2011 01:43:08 GMTDad - 2011-06-19 20:06:47http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsGOLD! Great stuff! Thanks Mike.f4cd8f961e8bba97af9d20a94102a13dSun, 19 Jun 2011 20:06:47 GMTEvgeniy Dzhurov - 2011-06-18 10:44:34http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsThanks for the article, it's quite useful. And I have one question to add. As I'm used to running gdb from Xcode and occasionally throw in commands as I learn, are there any significant capabilities that I'm missing out by not running the debugger separately as per your advice. Perhaps something must-know for day to day Xcode development?f49528d70c6850eef3aadc09ad298876Sat, 18 Jun 2011 10:44:34 GMTVasi - 2011-06-17 21:33:16http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsIf you want to provide arguments to the target at the command-line, you can use: <br /> <br /><code>gdb --args /path/to/executable arg1 arg2 etc</code>b08285b81b437a38017d0721d2293d35Fri, 17 Jun 2011 21:33:16 GMTRandy Becker - 2011-06-17 21:07:39http://www.mikeash.com/?page=pyblog/friday-qa-2011-06-17-gdb-tips-and-tricks.html#commentsGreat article, as always. I do wish you had mentioned <code>x/s</code>. I often use it to inspect selectors that will be passed to <code>objc_msgSend()</code>.3c5ee7c88169cba568117b662b29d233Fri, 17 Jun 2011 21:07:39 GMT