Skip to content

Debugging the c code

Erik B Knudsen edited this page Aug 17, 2021 · 4 revisions

McCode pre 3.0

#line pragmas

McCode (pre the 3.0 line of code-generators) uses #line-pragmas in the generated code, in an attempt to jump between each of the included c-snippets in libraries, components etc. This unfortunately does not work well in all cases.

  1. Some files are %included, which is a simple concatenation. If there is such a %include-statement the line numbering will be off.
  2. If there are more than one component of a single type, e.g two Guides or Mirrors, the #line-pragmas hide which component the debugger is currently stepping through.

A first advisable step is therefore to

grep -v ^\#line Instrument.c > Instrument_stripped.c

Debugging tips

Linux and windows

Use GDB: First, compile the generated c-code including debugging symbols.

gcc -g Instrument_stripped.c -o Instrument_stripped.out

On windows it may be preferrable to use the .exe-suffix for the executable.

Then start the debugger with

gdb Instrument_stripped.out

macOS

Use LLVM, here is a list of command equivalences https://lldb.llvm.org/use/map.html

Clone this wiki locally