{"id":634,"date":"2010-11-23T18:50:33","date_gmt":"2010-11-23T08:50:33","guid":{"rendered":"http:\/\/brnz.org\/hbr\/?p=634"},"modified":"2010-11-23T18:50:33","modified_gmt":"2010-11-23T08:50:33","slug":"assembly-primer-part-3-gdb-usage-primer","status":"publish","type":"post","link":"https:\/\/brnz.org\/hbr\/?p=634","title":{"rendered":"Assembly Primer Part 3 &#8212; GDB Usage Primer"},"content":{"rendered":"<p>These are my notes for where I can see both PPC and SPU varying from ia32, as presented in the video\u00a0<a href=\"http:\/\/www.securitytube.net\/Assembly-Primer-for-Hackers-%28Part-3%29-GDB-Usage-Primer-video.aspx\">Part 3 &#8212; GDB Usage Primer<\/a>. \u00a0The usage of gdb is effectively the same for all three architectures &#8212; I&#8217;ve noted here some of the differences in the program being debugged.<\/p>\n<p>In the ia32 disassembly of <a href=\"http:\/\/code.securitytube.net\/SimpleDemo.c\">SimpleDemo.c<\/a>, the <em>call<\/em> instruction is generated for function calls.<\/p>\n<p>When compiled for PPC, I see\u00a0<em>bl<\/em> &#8212; branch to address offset from <em>bl<\/em> instruction, placing the address of the following instruction in the link register (lr).<\/p>\n<p>When compiled for SPU, I see\u00a0<em>brsl<\/em> &#8212; branch to address offset from brsl instruction, placing the address of the following instruction into the specified register (typically r0, used as link register).<\/p>\n<p>Neither PPC nor SPU pass args on the stack (at least not for two scalar args as for the add function in SimpleDemo.c). \u00a0Those values can still be seen as being present on the stack when examining it in gdb. \u00a0The reason appears to be that when compiled with no optimisation, a number of registers are pushed to the stack that are not needed. \u00a0Compiling at -O1 eliminates the superfluous pushes, so the args are no longer visible there, being present in the appropriate registers when the function is called.<\/p>\n<p>(<a href=\"http:\/\/software.intel.com\/sites\/products\/documentation\/studio\/composer\/en-us\/2011\/compiler_c\/bldaps_cls\/common\/bldaps_calling_conv.htm\">This document on calling conventions from Intel<\/a> seems to say that args get passed to functions in regs where possible on ia32 as well&#8230; I can see it happening for amd64, not ia32)<\/p>\n<p>As noted above, PPC and SPU store the function return address in the link register (lr or r0), not on the stack.<\/p>\n<p>All three architectures appear to put the return value in a register (eax or r3).<\/p>\n<h3>Previous assembly primer notes\u2026<\/h3>\n<p>Part 1 \u2014 System Organization \u2014\u00a0<a href=\"https:\/\/brnz.org\/hbr\/?p=631\">PPC<\/a> \u2014\u00a0<a href=\"https:\/\/brnz.org\/hbr\/?p=632\">SPU<\/a><br \/>\nPart 2 &#8212; Memory Organisation &#8212; <a href=\"https:\/\/brnz.org\/hbr\/?p=633\">SPU<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>These are my notes for where I can see both PPC and SPU varying from ia32, as presented in the video\u00a0Part 3 &#8212; GDB Usage Primer. \u00a0The usage of gdb is effectively the same for all three architectures &#8212; I&#8217;ve noted here some of the differences in the program being debugged. In the ia32 disassembly &hellip; <a href=\"https:\/\/brnz.org\/hbr\/?p=634\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Assembly Primer Part 3 &#8212; GDB Usage Primer&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,26],"tags":[38,39,40],"_links":{"self":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/634"}],"collection":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=634"}],"version-history":[{"count":11,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/634\/revisions"}],"predecessor-version":[{"id":683,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/634\/revisions\/683"}],"wp:attachment":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}