ug4
|
We incorporated a logging mechanism into UG4 to faciliate printing messages for test purposes. To enable it, you need to make ug with
cmake -DDEBUG_LOGS=ON ..
(otherwise all UG_DLOG/IF_DEBUGs will be ignored).
It works like this: In your LUA-Script, you add the line
Note that the debugID structure is supported by the UGIDE code completion so you are more aware of which debugIDs exist or not.
Alternatively, you can use the old version of this: GetLogAssistant():set_debug_level("MAIN", 2)
Internally, it is debugID.MAIN = "MAIN"
.
Now the debug level for the DebugID MAIN is set to 2. Now in the C++ code, you can do logging with UG_LOG, using some ostream functionality like in cout:
If you want a message to be printed only if the DebugID MAIN is 2, you do
There's also a way to control if a block is exectuted or not:
By default, UG4 has the following DebugIDs:
For a complete list, use
in your script. You can also add custom debug IDs in the following way: You need to create one global object of the class DebugID (in a cpp-file):
Now you can use it in any C++ file this way
and set the debug level in lua
Alternatively GetLogAssistant():set_debug_level("MYAPP", 1)
.
Note the difference between the DebugID object DID_MYAPP and its associated string "MYAPP" - you can use for both the same, of course.
You can also subdivide Debug IDs: Say you have an app called "MYAPP" and some subfunctions "FUNC1" and "FUNC2". Then
Now you can do
To debug ug4, you have to make
cmake -DDEBUG=ON ..
Note GCC 4.1.2 .
Then you do
gdb ugshell b myfile.cpp:33 run -ex myscript.lua -myParameter1 3.4 -myOption2
Another possibility is use –args
gdb --args ugshell -ex myscript.lua -myParameter1 3.4 -myOption2 b myfile.cpp:33 run
For simple parallel debugging, see xprun .
Sometimes you cannot set breakpoints because the source is in a shared library. This is true for all plugins. Also ug4 is loaded dynamically from ugshell. There are two solutions for this:
cmake -DSTATIC_BUILD=ON ..
set breakpoint pending on
to avoid the y/n. Note that now gdb won't tell you if your filename was wrong. b SharedLibrariesLoaded
. After that, you'll be able to break in your plugin/ug4. Best way is to create a .gdbinit
file in your ug4/bin directory like this:
b SharedLibrariesLoaded run echo shared libraries now loaded.\n # add your breakpoints after this line # cont
Then you can start your code with
gdb --args ugshell -ex myscript.lua -myParameter1 3.4 -myOption2
and it will break right after all shared libraries have been loaded. Now you can add your breakpoints.
cont
after that, NOT run
.You can also add your breakpoints in the .gdbinit file and a cont
at the end. That way you'll have to type less.
You can debug your LUA code with the tools here: Debug Shell.
You can access the LUA debugger within GDB by writing in the gdb shell
This gives you the possibility to check LUA variables and the LUA execution position when your C++ code crashed.
cont
to get back to gdb, not quit.If you only need the current LUA execution position, use