OverviewThis page describes nacl64-gdb, an experimental Native Client Debugger based on GDB made specifically for debugging 64-bit Native Client modules on x86_64 Linux systems. For debugging 32-bit Native Client modules, refer to the corresponding documentation. InstallationGetting the SourceThis nacl64-gdb is not officially included in the toolchain or SDK. You can get it from the branch nacl of nacl-gdb repository:git clone http://git.chromium.org/native_client/nacl-gdb.git cd nacl-gdb git checkout naclBuildingConfigure and build as the native debugger: mkdir <build-dir>cd <build-dir><src-dir>/configure --prefix=<install-dir>make all-gdbmake install-gdbNow you have <install-dir>/bin/gdb. Copy or link it to nacl64-gdb for convenience.UsageThe debugger works by debugging the Service Runtime (see Glossary) together with the NaCl program. Thinking of the debugging techniques, simply treat NaCl program as yet another shared library loaded by the service runtime. ATTENTION: service runtime and NaCl program will likely have equally named symbols, for example, main function exists in both. This makes things like setting breakpoint on a particular main somewhat tricky. See detailed solutions below.Debugging in sel_ldrFirst you need to specify service runtime binary. Do it as usually: (gdb) file ./sel_ldrSpecify full command line for the service runtime: service runtime command-line arguments, NaCl binary and NaCl command line arguments (if applicable). With sel_ldr, we recommend to use -Q to disable platfrom qualification test, otherwise you might get a SIG_SEG at startup (however, you can simply continue from there):(gdb) set args -Q ./t.nexeUnfortunately for certain service runtime there is no way to deduce NaCl program name from the service runtime command line. For example, chrome gets NaCl program name from the html.For now, you always have to specify the NaCl binary explicitly, with this new gdb command:(gdb) nacl-file ./t.nexeHere is another example, for debugging NaCl dynamically linked executable. Here nacl-file is the dynamic loader:(gdb) set args -Q -c -a -f ./runnable-ld.so -- ./t.out(gdb) nacl-file ./runnable-ld.soAll of the above may be quite annoying. Make good use of gdb scripts and --command=<script> command line gdb option.Debugging in ChromeWORK IN PROGRESS. These notes are incomplete. Follow-up questions on debugging are welcome on native-client-discuss@googlegroups.com. Getting satisfactory results from nacl64-gdb requires binaries with symbolic information for your NaCl module. As with any debugging situation, NaCl modules should be built with -g and not stripped. If you want symbolic information for the browser as well you can find release builds of Chromium with symbolic information at http://commondatastorage.googleapis.com/chromium-browser-continuous/index.html. Typical workflow:
The workflow is helpful for situations where a crash happens relatively early, for example during initialization, and you would like to capture the crash in the debugger. You can forgo the part about suspending Chrome when hunting for bugs that happen in response to a user action. Another common debug scenario is an infinite loop. Keep in mind that sometimes a profiler can be a useful tool for finding such problems. See the Native Client developer pages on profiling. Setting BreakpointsIf the symbol is non-ambiguous, set the breakpoints as usually: (gdb) b NaClCreateMainThreadBreakpoint 1 at 0x259f8: file src/trusted/service_runtime/sel_ldr_standard.c, line 645.If setting breakpoint on NaCl symbol before NaCl program is loaded, gdb will ask if the breakpoint should be pending on future shared library load. Recall that NaCl program is treated as yet another shared library and answer 'y': (gdb) b hello_worldFunction "hello_world" not defined.Make breakpoint pending on future shared library load? (y or [n]) yBreakpoint 2 (hello_world) pending.If the symbol is ambiguous, breakpoint will be set on a symbol found by symbol lookup, which depends on the current context. And this might be not stable, and breakpoints may migrate when re-set, for example, at program restart. To avoid this, try to specify not only the symbol name, but the source file as well: (gdb) b sel_main.c:mainBreakpoint 3 at 0x7ffff7f640a8: file src/trusted/service_runtime/sel_main.c, line 147.(gdb) b t.c:mainBreakpoint 4 at 0x7ff4010005e4: file t.c, line 19.Sample session Here is an example for debugging dynamically linked executable: That's it. Known IssuesThe major known issue is that nacl64-gdb is not stable. Please provide feedback and report errors! |
