{"id":890,"date":"2016-09-09T22:15:03","date_gmt":"2016-09-09T20:15:03","guid":{"rendered":"http:\/\/lallafa.de\/blog\/?p=890"},"modified":"2016-09-09T22:15:03","modified_gmt":"2016-09-09T20:15:03","slug":"libtrace-a-library-function-tracer-for-fs-uae","status":"publish","type":"post","link":"https:\/\/lallafa.de\/blog\/2016\/09\/libtrace-a-library-function-tracer-for-fs-uae\/","title":{"rendered":"libtrace &#8211; a library function tracer for FS-UAE"},"content":{"rendered":"<p>During development traces are a really helpful source of information when doing debugging or if you simply want to understand how a system works. When developing for the classic <em>Amiga<\/em> platform you learn a lot about the inner workings of applications if you could see what library functions they call and what parameters they pass in and get out. You can observe its behavior without having the source code and all that almost live&#8230;<\/p>\n<p>Here <strong>libtrace<\/strong> comes into play: Its a debugging extension I have written for the famous <a href=\"https:\/\/fs-uae.net\">FS-UAE<\/a> Amiga emulator that allows you to take this look behind the scenes of the system: <strong>You can trace any library and any function set<\/strong> and you will see what function was called by printing its name, the arguments and the values passed in an out&#8230;<\/p>\n<p><!--more--><\/p>\n<h4>How does it work?<\/h4>\n<h5>Build FS-UAE with libtrace<\/h5>\n<p>First you need to build a new FS-UAE from source with the libtrace feature. Use my <a href=\"https:\/\/github.com\/cnvogelg\/fs-uae\/tree\/libtrace\">libtrace branch<\/a> on GitHub for this.<\/p>\n<h5>Configure Tracing<\/h5>\n<p>You need to write a small config text file that defines the trace profile, i.e. what libraries you want to see and what functions.<\/p>\n<p>Name the file e.g. <strong>libtrace.cfg<\/strong> with the following contents:<\/p>\n<pre>dos.library\r\nfd\/dos_lib.fd\r\n+*\r\n!Open\r\n#\r\nexec.library\r\nfd\/exec_lib.fd\r\nInitResident\r\n#<\/pre>\n<p>Here we will trace <em>dos.library<\/em> and <em>exec.library<\/em>. In dos we want to see all functions (*) but not the <strong>Open()<\/strong> call. In exec only the <em>InitResident()<\/em> function is traced. The <strong>.fd<\/strong> files need to reside on your host in the given directory (here in the fd folder of the current directory). Take them from the AmigaOS NDK.<\/p>\n<p>See the <a href=\"https:\/\/github.com\/cnvogelg\/fs-uae\/blob\/libtrace\/doc\/libtrace.md\">libtrace documentation<\/a> for more details on the config file<\/p>\n<h5>Enable Tracing<\/h5>\n<p>Now run FS-UAE and enter the debugger with <strong>F11+d<\/strong>.<\/p>\n<p>In the Debugger load the config file and enable tracing:<\/p>\n<pre>Lc 'libtrace.cfg'\r\nLe 1\r\nx<\/pre>\n<p>Exit the debugger and reset your Amiga to activate the trace (<strong>F11+r<\/strong>).<\/p>\n<p>With the new Amiga startup you should see the traces popping in on your console.<\/p>\n<p>It looks like this:<\/p>\n<pre>@00f81014 0000f8c8:Initial CLI exec InitResident(resident[a1]=00fbf080, segList[d1]=00000000)\r\n@00fbf100 0000f8c8:Initial CLI dos CreateProc(name[d1]=00fbf09a, pri[d2]=00000000, segList[d3]=003efcdb, stackSize[d4]=00000800)\r\n@00fbf100 0000f8c8:Initial CLI dos CreateProc -&gt; d0=0001bd44\r\n@00f81014 0000f8c8:Initial CLI exec InitResident -&gt; d0=000160e0\r\n@00fb85f0 0001c620:CON dos WaitPkt()\r\n@00fb85f0 0001c620:CON dos WaitPkt -&gt; d0=0001c5f0\r\n@00fb85f0 0001c620:CON dos [DosPkt: Type=00000000 Args=00005883,00000000,0000084b,00000000 Res=00000000,00000000]\r\n@00fb8490 0001c620:CON dos StrToLong(string[d1]=0001e06c, value[d2]=0001d0b8)\r\n@00fb8490 0001c620:CON dos StrToLong -&gt; d0=ffffffff<\/pre>\n<p>You&#8217;ll see the <strong>PC<\/strong> calling the function, the <strong>exec task<\/strong> with name, the <strong>lib<\/strong> and finally the <strong>function<\/strong> with all argument names and values. A second line reports the return of the function and prints the <strong>result value<\/strong>.<\/p>\n<p>You can filter the trace and focus on a single task if you give its name in the debugger with the <strong>Lt<\/strong> option. Furthermore, you can write the traces to a file instead of the console with the <strong>Lo<\/strong> command.<\/p>\n<pre>Lt 'CON'\r\nLo 'out.txt'<\/pre>\n<p>That&#8217;s it&#8230; Read the <a href=\"https:\/\/github.com\/cnvogelg\/fs-uae\/blob\/libtrace\/doc\/libtrace.md\">libtrace doc <\/a>for more details and a technical description of the inner workings of this feature.<\/p>\n<p>Have Fun and Happy Amiga Coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>During development traces are a really helpful source of information when doing debugging or if you simply want to understand how a system works. When developing for the classic Amiga platform you learn a lot about the inner workings of &hellip; <a href=\"https:\/\/lallafa.de\/blog\/2016\/09\/libtrace-a-library-function-tracer-for-fs-uae\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,17],"tags":[],"class_list":["post-890","post","type-post","status-publish","format-standard","hentry","category-amiga","category-fs-uae"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/piBMF-em","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/comments?post=890"}],"version-history":[{"count":3,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/890\/revisions"}],"predecessor-version":[{"id":893,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/890\/revisions\/893"}],"wp:attachment":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/media?parent=890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/categories?post=890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/tags?post=890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}