Arria 10 SoC Virtual Platform User Guide

ID 683326
Date 9/16/2015
Public
Document Table of Contents

1.6.6. Debugging Using the gdb Client on the Host

  1. Run the gdb client on the host:
    gdb-multiarch ./factorial.out
    Process ./factorial.out created; pid = 229
    Listening on port 8080
  2. Connect gdb to the target.
    Note: This example uses localhost:3624 instead of 192.168.0.9:8080 as shown in the VLAN port mapping found in the "Network Connectivity" section.
    (gdb) target remote localhost:3624
    Remote debugging using localhost:3624
    warning: Unable to find dynamic linker breakpoint function.
    GDB will be unable to debug shared library initializers
    and track explicitly loaded dynamic code.
    0x76fcfb00 in ?? ()
  3. Use the following gdb sample commands to debug the code:
    • b main: Set a breakpoint at the main function
    • c: Continue until the breakpoint is hit
    • s: Step one instruction
    • b 14: Insert a breakpoint at line 14
    • c typed multiple times: Run through iterations of the loop
    • l: List code

    The host console looks similar to the view below:

    <name>@ubuntu-12:~$ gdb-multiarch ./factorial.out
    GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1)7.4-2012.04
    Copyright (C) 2012 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    For bug reporting instructions, please see:
    <http://bugs.launchpad.net/gdb-linaro/>...
    Reading symbols from /home/<name>/factorial.out...done.
    (gdb) target remote localhost:3624
    Remote debugging using localhost:3624
    warning: Unable to find dynamic linker breakpoint function.
    GDB will be unable to debug shared library initializers
    and track explicitly loaded dynamic code.
    0x76fcfb00 in ?? ()
    (gdb) b main
    Cannot access memory at address 0x0
    Breakpoint 1 at 0x83ce: file factorial.c, line 12.
    (gdb) c
    Continuing.
    warning: Could not load shared library symbols for 2 libraries, e.g. 
    /lib/libc.so.6.
    Use the "info sharedlibrary" command to see the complete listing.
    Do you need "set solib-search-path" or "set sysroot"? 
    
    Breakpoint 1, main () at factorial.c:12
    12         for (i = 0; i < 10; ++i) {
    (gdb) l
    7     }
    8     
    9     int main () {
    10         int i;
    11         int n;
    12         for (i = 0; i < 10; ++i) {
    13                n = factorial (i);
    14                printf ("factorial(%d) = %d\n", i, n);
    15         }
    16         return 0;
    (gdb) b 14
    Breakpoint 2 at 0x83de: file factorial.c, line 14.
    (gdb) c
    Continuing. 
    Breakpoint 2, main () at factorial.c:14
    14                printf ("factorial(%d) = %d\n", i, n);
    (gdb) s
    Cannot access memory at address 0x0 
    Breakpoint 2, main () at factorial.c:14
    14                printf ("factorial(%d) = %d\n", i, n);
    (gdb) c
    Continuing. 
    Breakpoint 2, main () at factorial.c:14
    14                printf ("factorial(%d) = %d\n", i, n);
    (gdb) c
    Continuing. 
    Breakpoint 2, main () at factorial.c:14
    14                printf ("factorial(%d) = %d\n", i, n);
    (gdb) c
    Continuing. Breakpoint 2, main () at factorial.c:14
    14                printf ("factorial(%d) = %d\n", i, n);
    (gdb) c
    Continuing. 
    Breakpoint 2, main () at factorial.c:14
    14                printf ("factorial(%d) = %d\n", i, n);
    (gdb) c

    The target console looks similar to the view below:

    root@host:~# gdbserver :8080 ./factorial.out
    Process ./factorial.out created; pid = 229
    Listening on port 8080
    Remote debugging from host 192.168.0.1
    factorial(0) = 1
    factorial(1) = 1
    factorial(2) = 2
    factorial(3) = 6
    factorial(4) = 24
    factorial(5) = 120
    factorial(6) = 720
    factorial(7) = 5040
    factorial(8) = 40320
    factorial(9) = 362880 
    
    Child exited with status 0