How-to:Advanced:GDB: Difference between revisions

From Project Skyfire
Jump to navigation Jump to search
(Created page with "Category: Guides for Trinity {{Back-to:World:How-to:Advanced}} '''GDB: The GNU Project Debugger''' This is a simple/dirty tutorial of what is GDB and how to use it. Th...")
 
No edit summary
 
Line 1: Line 1:
[[Category: Guides for Trinity]]
[[Category: Guides for SkyFire]]
{{Back-to:World:How-to:Advanced}}
{{Back-to:World:How-to:Advanced}}


Line 7: Line 7:
This is a simple/dirty tutorial of what is GDB and how to use it.
This is a simple/dirty tutorial of what is GDB and how to use it.


This tutorial asumes that you can start your trinity-core by typing:
This tutorial asumes that you can start your skyfire by typing:
<pre>
<pre>
trinity-core
skyfire
</pre>
</pre>
in the console.
in the console.


1. Before you start debugging trinity you need to have ensured that it is compiled with debug information. To build trinity with debug info just add -DWITH_COREDEBUG=1 to your options when running cmake. Then compile and install trinity as usual.
1. Before you start debugging skyfire you need to have ensured that it is compiled with debug information. To build skyfire with debug info just add -DWITH_COREDEBUG=1 to your options when running cmake. Then compile and install skyfire as usual.
If you want really full debug, without optimization, you can pass -DCMAKE_BUILD_TYPE=Debug as a cmake option. This however might be particulary slow and take a huge amount of ram while compiling.
If you want really full debug, without optimization, you can pass -DCMAKE_BUILD_TYPE=Debug as a cmake option. This however might be particulary slow and take a huge amount of ram while compiling.


2. Now you can start trinity with gdb by typing this.
2. Now you can start skyfire with gdb by typing this.
<pre>
<pre>
gdb trinity-core
gdb skyfire
</pre>
</pre>
Then you will most likely see something like this:
Then you will most likely see something like this:
<pre>
<pre>
user@*:~/home/sources/build$ gdb trinity-core
user@*:~/home/sources/build$ gdb skyfire
GNU gdb 6.8-debian
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
Copyright (C) 2008 Free Software Foundation, Inc.
Line 34: Line 34:
(gdb) - is the GDB command prompt , here you can type some commands, almost like in normal shell.
(gdb) - is the GDB command prompt , here you can type some commands, almost like in normal shell.


Now after you have gdb running, you may instruct it to start trinity (by having gdb start trinity you can debug it), here is the command:
Now after you have gdb running, you may instruct it to start skyfire (by having gdb start skyfire you can debug it), here is the command:
<pre>
<pre>
run
run
</pre>
</pre>
Just type it and if you are lucky you will have trinity loading.
Just type it and if you are lucky you will have skyfire loading.


Ok ... you made it, now trinity runs. Take a break until it crash, then you can come back
Ok ... you made it, now skyfire runs. Take a break until it crash, then you can come back


3. When trinity crashes you will most likely see this message, or any similar.
3. When skyfire crashes you will most likely see this message, or any similar.


<pre>
<pre>
Line 94: Line 94:
Now you can start the whole monster with:
Now you can start the whole monster with:
<pre>
<pre>
gdb trinity-core --batch -x /path/to/gdb-commands
gdb skyfire --batch -x /path/to/gdb-commands
</pre>
</pre>


Line 101: Line 101:
1.You can also redirect stdout to some log file. I mean this:
1.You can also redirect stdout to some log file. I mean this:
<source lang="bash">
<source lang="bash">
gdb trinity-core --batch -x /path/to/gdb-commands > /some/log/file
gdb skyfire --batch -x /path/to/gdb-commands > /some/log/file
</source>
</source>


Line 112: Line 112:
3. You can add -ggdb3 -g3 flags to your CXXFLAGS in order to get more debug output. If you add them there is no need to add --with-debug-info switch in order to get meaningfull backtrace.
3. You can add -ggdb3 -g3 flags to your CXXFLAGS in order to get more debug output. If you add them there is no need to add --with-debug-info switch in order to get meaningfull backtrace.


4. You can pass arguments to trinity-core by passing them to the run gdb command ( run -c /path/to/trinitycore.conf ).
4. You can pass arguments to skyfire by passing them to the run gdb command ( run -c /path/to/worldserver.conf ).




-- original by Derex
-- original by Derex

Latest revision as of 17:01, 21 January 2013

Back to How-to:Advanced Guides list.


GDB: The GNU Project Debugger

This is a simple/dirty tutorial of what is GDB and how to use it.

This tutorial asumes that you can start your skyfire by typing:

skyfire

in the console.

1. Before you start debugging skyfire you need to have ensured that it is compiled with debug information. To build skyfire with debug info just add -DWITH_COREDEBUG=1 to your options when running cmake. Then compile and install skyfire as usual. If you want really full debug, without optimization, you can pass -DCMAKE_BUILD_TYPE=Debug as a cmake option. This however might be particulary slow and take a huge amount of ram while compiling.

2. Now you can start skyfire with gdb by typing this.

gdb skyfire

Then you will most likely see something like this:

user@*:~/home/sources/build$ gdb skyfire
GNU gdb 6.8-debian
Copyright (C) 2008 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"...
(gdb)

(gdb) - is the GDB command prompt , here you can type some commands, almost like in normal shell.

Now after you have gdb running, you may instruct it to start skyfire (by having gdb start skyfire you can debug it), here is the command:

run

Just type it and if you are lucky you will have skyfire loading.

Ok ... you made it, now skyfire runs. Take a break until it crash, then you can come back

3. When skyfire crashes you will most likely see this message, or any similar.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x42c5c950 (LWP 9283)]
Player (this=0x42c598e0, session=0x0) at ../../../src/game/Player.cpp:265
265    ../../../src/game/Player.cpp: No such file or directory.
    in ../../../src/game/Player.cpp
(gdb)

Now you can type some comands to get information about the crash, and possibly give it to some dev to fix the problem.

Here are the commands that are best to be typed ( or at least I find the most usefull for crash report )

shell echo -e "\nCRASH ON" `date`
info program
shell echo -e "\nBACKTRACE\n"
bt
shell echo -e "\nBACKTRACE FULL\n"
bt full
shell echo -e "\nTHREADS\n"
info threads
shell echo -e "\nTHREADS BACKTRACE\n"
thread apply all bt full

Just type them one after another and give the output in your bug report ...

OK. Thats it, now we can think of some way to automate all this process. GDB has 2 very good switches:

--batch            Exit after processing options.
--command=FILE, -x Execute GDB commands from FILE.

4. So you can put all the commands in one file and have GDB execute it, and when it finishes to exit. Lets say we put this in one file called gdb-commands.

run
shell echo -e "\nCRASH ON" `date`
info program
shell echo -e "\nBACKTRACE\n"
bt
shell echo -e "\nBACKTRACE FULL\n"
bt full
shell echo -e "\nTHREADS\n"
info threads
thread apply all bt full

Now you can start the whole monster with:

gdb skyfire --batch -x /path/to/gdb-commands


[TIPS] 1.You can also redirect stdout to some log file. I mean this: <source lang="bash"> gdb skyfire --batch -x /path/to/gdb-commands > /some/log/file </source>

2.You can add a tail command to gdb-commands file to get the latest lines from your server.log file: <source lang="bash"> shell echo -e "\nSERVER.LOG\n" shell tail -n 50 /path/to/your/server.log[/code]50 means how much lanes to take from server.log </source>

3. You can add -ggdb3 -g3 flags to your CXXFLAGS in order to get more debug output. If you add them there is no need to add --with-debug-info switch in order to get meaningfull backtrace.

4. You can pass arguments to skyfire by passing them to the run gdb command ( run -c /path/to/worldserver.conf ).


-- original by Derex