| Article Index |
|---|
| GDB UPC Sample Sessions |
| Multiple Unix Processes |
| Single Unix Process |
| Multiple Posix Threads |
| Single Thread Debugging |
| All Pages |
Sample debugging sessions are intended to better illustrate GDB-UCP features for debugging of the UPC programs. A simple UPC example program is used throughout this document.
Multiple Unix Processes
Compile Options
-g -O0 -dwarf-2-upc
Debugging Options
set pagination off set target-async on set detach-on-fork off set non-stop on set upcstartgate on
Sample Debugging Session
Compile example code:
$ upc -fupc-threads-4 -g -O0 -dwarf-2-upc \
-o upc-example upc-example.upc
Create GDB's startup file .gdbinitin the current directory with the following content:
set pagination off set target-async on set detach-on-fork off set non-stop on set upcstartgate on
Note: You may chose to create another file instead of .gdbinit. In this case you will need to run GDB UPC with "-x your-startup-file" option.
Specify UPC Debugging Assistant shared library for GCC UPC compiler:
csh shell: $ setenv UDA_GUPC_PLUGIN_LIBRARY [...]/plugin/uda-plugin.so bash shell: $ UDA_GUPC_PLUGIN_LIBRARY=[...]/plugin/uda-plugin.so $ export UDA_GUPC_PLUGIN_LIBRAR
Make sure that GDB on your path is indeed GDB UPC. For example:
$ gdb -v GNU gdb (GDB) 7.1.50.2 20100918 (GDB UPC/dev) Copyright (C) 2010 Free Software Foundation, Inc. [...] For bug reporting instructions, please see: [...]
At this point you can start your debugging session.
$ gdb upc_example [...] (gdb) r Starting program: /eng/upc/dev/nenad/GDB UPC-dev/examples/upc-example upc_lang: using GUPC plugin. UPC Threads sync debugging is on. Use upc-sync command to stop all threads and lift the debugging gate. [New UPC Thread 0] [New UPC Thread 1] [New UPC Thread 2] [New UPC Thread 3]
At this point all four threads have been created by the run-time, GDB UPC is using GCC UPC plug-in for UPC language debugging, and GCC UPC run-time's thread synchronization is in place.
(gdb) upc-sync UPC Mode activated. (gdb-upc)
At this point upc-sync command stops all the threads and sets upc UPC debugging mode of debugging. You can set a breakpoints at the main UPC function and continue all of the threads. Note that collective breakpoint is inserted.
(gdb-upc) b upc_main Breakpoint 1 at 0x4016cd: file upc-example.upc, line 23. (5 locations) (gdb-upc) c Continuing. Current language: auto The current source language is "auto; currently upc". Breakpoint 1, main () at upc-example.upc:23
All threads reached the same point in the code. You can continue debugging by inserting more breakpoints.
(gdb-upc) b 44 Breakpoint 2 at 0x401ab3: file upc-example.upc, line 44. (4 locations) (gdb-upc) c
Continuing. Breakpoint 2, main () at upc-example.upc:44 44 for (i = 0; i < BLKS_PER_THREAD; ++i)
Verify that all threads are at the same location:
(gdb-upc) info threads 3 UPC Thread 3 main () at upc-example.upc:44 2 UPC Thread 2 main () at upc-example.upc:44 1 UPC Thread 1 main () at upc-example.upc:44 * 0 UPC Thread 0 main () at upc-example.upc:44
You might want to take a look at some local and shared variables. Use UPC alias ua to execute GDB commands on all threads (alias to thread apply all)
(gdb-upc) ua p lthr_cnt
UPC thread 3:
$1 = {0, 0, 0, 3}
UPC thread 2:
$2 = {0, 0, 2, 0}
UPC thread 1:
$3 = {0, 1, 0, 0}
UPC thread 0:
$4 = {0, 0, 0, 0}
(GDB UPC) ua p thr_cnt
UPC thread 3:
$5 = {0, 1, 2, 3}
UPC thread 2:
$6 = {0, 1, 2, 3}
UPC thread 1:
$7 = {0, 1, 2, 3}
UPC thread 0:
$8 = {0, 1, 2, 3}
Continue all threads and exit:
(gdb-upc) c Continuing. [UPC Thread 2 exited] [UPC Thread 3 exited] [UPC Thread 1 exited] [UPC Thread 0 exited] UPC Mode de-activated. Program exited normally. (gdb-upc) quit $
Debugging of only one UPC thread as a Unix process is similar to debugging multiple of them. The only difference is in the start-up code where thread start synchronization gate is not used at all. In this case the user can simple insert the breakpoint in the main UPC function and start running the application. One the break point is reached, upc-sync command can be used to switch GDB UPC into the UPC mode.
Single Unix Process |
|
| Compile Options | |
| -g -O0 -dwarf-2-upc |
|
| Debugging Options | |
| set pagination off set target-async on set detach-on-fork off set non-stop on set upcstartgate on |
|
| Sample Debugging Session | |
Compile example code (static or dynamic thread allocation can be used):
$ upc -fupc-threads-1 -g -O0 -dwarf-2-upc \Create GDB's startup file .gdbinitin the current directory with the following content: set pagination off Note: You may chose to create some other file instead of .gdbinit.In this case you will need to run GDB UPC with "-x your-startup-file" option. Specify UPC Debugging Assistant shared library for GCC UPC compiler: csh shell: Make sure that GDB on your path is indeed GDB UPC. For example: $ gdb -v At this point you can start your debugging session. $ gdb upc_example At this point the only UPC thread is running, however GDB UPC is still in the GDB mode. Execute upc-init command to enable the UPC mode and initalize UDA plugin. (gdb) upc-initAs you are working with only one thread collective features of GDB UPC (breakpoint, stepping) don't have any effect on debugging. |
|
Multiple Posix Threads
Pthreads implementation is another variant of GCC UPC run-time where each thread is mapped into pthreads instead of Unix processes. Pthreads run-time does not use UPC threads start-up synchronization.
Compile Options
-g -O0 -dwarf-2-upc -fupc-pthreads-model-tls
Debugging Options
set pagination off set target-async on set detach-on-fork off set non-stop on
Sample Debugging Session
Compile example code (static or dynamic thread allocation can be used):
$ upc -fupc-threads-4 -fupc-pthreads-model-tls -g -O0 -dwarf-2-upc \
-o upc-example upc-example.upc
Create GDB's startup file .gdbinitin the current directory with the following content:
set pagination off set target-async on set detach-on-fork off set non-stop on
Note: You may choose to create some other file instead of .gdbinit. In this case you will need to run GDB UPC with "-x your-startup-file" option.
Note: GDB UPC upcstartgate option is not necessary as one thread GCC UPC run-time does not uses thread synchronization mechanism.
Specify UPC Debugging Assistant shared library for GCC UPC compiler:
csh shell: $ setenv UDA_GUPC_PLUGIN_LIBRARY [...]/plugin/uda-plugin.so bash shell: $ UDA_GUPC_PLUGIN_LIBRARY=[...]/plugin/uda-plugin.so $ export UDA_GUPC_PLUGIN_LIBRAR
Make sure that GDB on your path is indeed GDB UPC. For example:
$ gdb -v GNU gdb (GDB) 7.1.50.2 20100918 (GDB UPC/dev) Copyright (C) 2010 Free Software Foundation, Inc. [...]
For bug reporting instructions, please see: [...]
At this point you can start your debugging session.
$ gdb upc_example [...] (gdb) b upc_main Breakpoint 1 at 0x4016cd: file upc-example.upc, line 23. (gdb) r [Thread debugging using libthread_db enabled] upc_lang: using GUPC plugin. [New UPC Thread 0] [New UPC Thread 1] [New UPC Thread 2] [New UPC Thread 3] Breakpoint 1, main () at upc-example.upc:23 23 if (!MYTHREAD) Current language:· auto The current source language is "auto; currently upc". Breakpoint 1, main () at upc-example.upc:23 23 if (!MYTHREAD) Breakpoint 1, main () at upc-example.upc:23 23 if (!MYTHREAD) Breakpoint 1, main () at upc-example.upc:23 23 if (!MYTHREAD) Starting program: /eng/upc/dev/nenad/GDB UPC-dev/examples/upc-example Breakpoint 1, main () at upc-example.upc:23 23 if (!MYTHREAD)
Current language:· auto The current source language is "auto; currently upc". (gdb)
At this point all of the UPC threads are running, however as GDB UPC is still in the GDB mode, all threads report a breakpoint event.· Execute upc-sync command to switch debugging into the UPC mode.
(gdb) upc-sync UPC Mode activated. (gdb-upc) info threads 3 UPC Thread 3· main () at upc-example.upc:23 2 UPC Thread 2· main () at upc-example.upc:23 1 UPC Thread 1· main () at upc-example.upc:23 * 0 UPC Thread 0· main () at upc-example.upc:23 (gdb-upc)
Continue debugging of your program.
Single Thread Debugging
There are situations where the user needs to debug a single thread out of many UPC threads. This can be achieved by switching from GDB UPC's upc mode into the regular gdb mode. For example:
(
with-upc-pts=struct
(gdb-upc) set upcmode off
UPC Mode de-activated.
(gdb) thread 3
[Switching to thread 3 (UPC Thread 1)]#0· \
main () at upc-example.upc:23
23 if (!MYTHREAD)<
(gdb) n
27 upc_barrier;
(gdb)info threads
5 UPC Thread 3 main () at upc-example.upc:23
4 UPC Thread 2 main () at upc-example.upc:23
* 3 UPC Thread 1 main () at upc-example.upc:27
2 UPC Thread 0 main () at upc-example.upc:23
1 UPC MONITOR 0x0000003d51007fbd in \
pthread_join () from /lib64/libpthread.so.0
(gdb)
As seen from above example, only a single UPC thread (UPC thread number 1) is advanced for one source instruction. Note that in GDB mode GDB thread numbers must be used.








