View Single Post
  #4   (View Single Post)  
Old 30th January 2016
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,987
Default

There are generally three types of debugging:
  1. Application debug messages, written into the application by a developer. These may be turned on by various application dependent flags, from things like a "-v" option for "verbose," or by tokens set with the -D compiler flag, used at compiler pre-processing time.
  2. Debugging symbols inserted into the compiled object code, for use with a debugger. I mentioned one in my first reply: the GNU debugger, gdb(). With a debugger you can step through the operation at a source code level, or, even at a machine code level. You can set breakpoints, look at variable and structure values, assign new variable values, and watch an application as it runs step by step.
  3. OS-specific system call ("syscall") tracing tools.
Your debugging was type 1. I'd thought you meant type 2. To enable type 2 debugging:
  • We tell the compiler to enable debugging symbols in the object produced, so that source code file names, source code line numbers, and source code variable names and types are all recorded in the compiled object. This is done with the -g compiler flag.
  • We may also tell the compiler to turn off all optimizations. The program will run more slowly, but variable values won't be hidden from a debugger by having been "optimized out" through storing their values in CPU registers, or other shortcuts the compiler may apply. This is done with the -O0 flag. Capital "Oh" for optimization, and zero for none.
  • We may also tell the install script that packages and/or installs the final program not to strip symbols from the final executable. Most standard packaging tools will do that with a strip(1) command. My OS doesn't use pkgsrc, we use different tools, and to disable stripping of symbols at install, I set a line in my port Makefile with
    Code:
    INSTALL_STRIP=
    so that it doesn't run the strip(1) command. I don't need to do this when I run the binary out of the build directory, rather than installing it. You may not need to disable strip(1) if you do not install the binary.
I don't know much about tor, but I know it uses GNU-style configuration tools. You can add C compiler flags and C++ compiler flags with options such as:
Code:
CFLAGS+=-g -O0
CXXFLAGS+=-g -O0
when the GNU configure script is run. You may need to quote the options, depending how the script is called. I always use "+=" rather than "=" and place them after other compiler flags, if any. This is because the last -O level used wins. If you place -O0 before the makefile requested -O2, level 2 optimization will be used by the compiler.

Last edited by jggimi; 30th January 2016 at 05:21 PM. Reason: clarity, and one thinko
Reply With Quote