[GNC-dev] debug info

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[GNC-dev] debug info

c.holtermann
Hello,

when debugging for my recent pull request #439 I needed to use
gdb. When compiling the maint branch from github I didn't have debug
information (line numbers) in gdb. I needed to add them by including
the -g flag in CMakelLists.txt. I did it only for c and not for c++.
Patch below for illustrative purposes.

Wouldn't it be good to have a command line option or environment
variable to enable that debug information for c and c++ ?

regards,

Christoph Holtermann

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 860954143..5527cd99e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -567,7 +567,7 @@ set(CMAKE_CXX_FLAGS "-std=gnu++11
${CMAKE_CXX_FLAGS}")  # FIXME: should be -std=


  if (UNIX)
-  set( CMAKE_C_FLAGS "-Werror -Wdeclaration-after-statement
-Wno-pointer-sign -Wall -Wmissing-prototypes -Wmissing-declarations
-Wno-unused ${CMAKE_C_FLAGS}")
+  set( CMAKE_C_FLAGS "-g -Werror -Wdeclaration-after-statement
-Wno-pointer-sign -Wall -Wmissing-prototypes -Wmissing-declarations
-Wno-unused ${CMAKE_C_FLAGS}")
    set( CMAKE_C_FLAGS "-Wno-deprecated-declarations -std=gnu11
-Wno-error=parentheses ${CMAKE_C_FLAGS}")
    set( CMAKE_CXX_FLAGS "-Werror -Wall -Wmissing-declarations
-Wno-unused -Wno-error=parentheses ${CMAKE_CXX_FLAGS}")
    set( CMAKE_CXX_FLAGS "-Wno-deprecated-declarations
${REGISTER_CXXFLAG} ${CMAKE_CXX_FLAGS}")
_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel
Reply | Threaded
Open this post in threaded view
|

Re: [GNC-dev] debug info

John Ralls-2


> On Dec 15, 2018, at 6:16 AM, [hidden email] wrote:
>
> Hello,
>
> when debugging for my recent pull request #439 I needed to use
> gdb. When compiling the maint branch from github I didn't have debug
> information (line numbers) in gdb. I needed to add them by including
> the -g flag in CMakelLists.txt. I did it only for c and not for c++.
> Patch below for illustrative purposes.
>
> Wouldn't it be good to have a command line option or environment
> variable to enable that debug information for c and c++ ?

Christoph,

Of course. That’s why Cmake provides CMAKE_BUILD_TYPE. To make a debug build, add the argument -D CMAKE_BUILD_TYPE=Debug to your cmake invocation.

BTW, the flags passed to the compilers are also modifiable from the command line using CMAKE_C_FLAGS and CMAKE_CXX_FLAGS. No need to change CMakeLists.txt.

Should you ever need to do this for an autotools project the equivalents are the environment variables CFLAGS and CXXFLAGS; autotools also reads CPPFLAGS and applies the contents to both c and c++ compiles. Autotools unfortunately doesn’t have an equivalent to CMAKE_BUILD_TYPE so you have to adjust the compiler flags.

Regards,
John Ralls

_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel
Reply | Threaded
Open this post in threaded view
|

Re: [GNC-dev] debug info

c.holtermann
Am 2018-12-15 17:19, schrieb John Ralls:

>> On Dec 15, 2018, at 6:16 AM, [hidden email] wrote:
>>
>> Hello,
>>
>> when debugging for my recent pull request #439 I needed to use
>> gdb. When compiling the maint branch from github I didn't have debug
>> information (line numbers) in gdb. I needed to add them by including
>> the -g flag in CMakelLists.txt. I did it only for c and not for c++.
>> Patch below for illustrative purposes.
>>
>> Wouldn't it be good to have a command line option or environment
>> variable to enable that debug information for c and c++ ?
>
> Christoph,
>
> Of course. That’s why Cmake provides CMAKE_BUILD_TYPE. To make a debug
> build, add the argument -D CMAKE_BUILD_TYPE=Debug to your cmake
> invocation.
>
> BTW, the flags passed to the compilers are also modifiable from the
> command line using CMAKE_C_FLAGS and CMAKE_CXX_FLAGS. No need to
> change CMakeLists.txt.
>
> Should you ever need to do this for an autotools project the
> equivalents are the environment variables CFLAGS and CXXFLAGS;
> autotools also reads CPPFLAGS and applies the contents to both c and
> c++ compiles. Autotools unfortunately doesn’t have an equivalent to
> CMAKE_BUILD_TYPE so you have to adjust the compiler flags.
>
> Regards,
> John Ralls

John,

thank you for that. It was very helpful. I think I didn't find this
information
on the wiki. Maybe I overlooked it but I'll see if I can add it to the
wiki.

regards,

Christoph Holtermann
_______________________________________________
gnucash-devel mailing list
[hidden email]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel