how can I debug binutils to check assembler options - c

how to debug gnu binutils
I want to check code flow for assembler option
I have following assembler option
/gas/as-new --statistics -o dump.o a.s
how can I debug binutils. I have ddd debugger and I have also used -g option in the configuration option which will give me debugging information but what next ??

Related

How to emit debug information using llvm ir in Clang?

Using clang or clang++ the command of
clang -S -emit-llvm ./source.c
will create a llvm ir document. However debugging information is missing. So when you test and compile things you lose debugging information.
How does one can make clang emit human readable llvm ir document with debug information ?
The standard option to add debug info is -g. So, running clang -g -S -emit-llvm source.c will emit necessary information

How to use GNU gprof profiler on macOS Mojave?

I want to use GNU gprof that comes with GCC to profile my C program. However, it returns __dyld section not supported error when I compile with the -pg flag and try to run the program:
$ gcc -pg main.c
$ ./a.out
dyld: __dyld section not supported in /Users/evgenii/Downloads/c_profile/./a.out
This error has been reported here. Is there a way to use the GNU profiler on macOS Mojave? I'm aware that there are alternative tools for profiling, but I want to use gprof.

GNOME Builder: "A suitable debugger can't be found" error

I am trying to debug a sample program in Gnome Builder IDE that is written in C, but there is a pop up each time I am pressing the "Debug" button, that says "Failed to initialize debugger: a suitable debugger could not be found".
I am using Manjaro Linux XFCE, the project is make-based, so no meson.
Here is a part of my makefile:
all: koala
WARNINGS = -Wall
DEBUG = -fno-omit-frame-pointer -g
OPTIMIZE = -O2
koala: Makefile koala.c
gcc -o $# $(WARNINGS) $(DEBUG) $(OPTIMIZE) koala.c -lm
UPD: Tried debugging on some sample project with Meson - it works. Now I want to figure out how to use it with make projects.
Same issue here: have a C++ project I am building with make on gnome-builder 3.38 and no chance to spawn gdb from the UI.
By searching the Gnome forums, it appears that at the time I am writing this answer Builder doesn't know how to execute the final executable/environment through make. Hence it cannot launch GDB.
Meson is the only option to graphically debug in Builder for now and since Builder is very much targeting Gnome applications develoment, hence Meson, I have not seen a clear roadmap to support GDB via make.

cannot single-step source but assembly single-step and breakpoints work ok

I have a C application running on embedded ARM M4; it works correctly.
I use Kinetis Design Studio, which uses gdb, as my debugger on Windows.
For most of my .obj, I can single-step the C source. However, for a few files, although I can use breakpoints, single-stepping the C source doesn't work: pressing Single-step causes debugger to act as if I pressed Run but the app is definitely not running.
But single-stepping the assembly, same .obj files, works correctly.
I use the same compile options for all .c
-x c -Wall -Werror -std=c99 -nostdlib -mthumb -mtune=cortex-m4 -mlittle-endian -Wdouble-promotion -DNDEBUG -fdata-sections -ffunction-sections -c -save-temps=obj -g3 -gdwarf-2
QUESTION
For some .obj, why do the breakpoints and assembly single-step work but not the source single-step?
You could provide some more information and what you tried so far. For example, what is the difference in those object files? Are it always the same? Do they have specific dependencies to non-user-code or are they non-user-code? What are you debugger-options? Based on that, I can just give basic advice:
-Check the correctness of your symbol file configuration / that they are in sync with the binary and loaded correctly.
-Be sure that there are no changes to the source code after compilation, so the IDE cannot falsely shows code that does not exist in you latest compilation (which is not debuggable).
-Consider to deactivate options like JustMyCode - depending on your environment (https://learn.microsoft.com/de-de/visualstudio/debugger/just-my-code?view=vs-2017)
-Check your debugger options

How can I use debug version of glibc to build a program?

i want to debug something in glibc, so i want to use a debug version of glibc to build the program.
if i just use "gcc -o test test.c" to build the program,
apt-get install libc6-dbg
apt-get source libc6-dev
when i was debugging the programs,some val is told that it is optimized. and EIP is always jump back.
how can i debug the debug version of glibc.
Caveat: I use fedora but it has a similar mechanism.
The debug package downloads an additional file that has the debug information you would get if you compiled with -g for glibc.
But, this package matches the standard build which is built with optimization (e.g. -O2).
It's the optimization that is causing the behavior you're seeing. So, the gdb "coverage" will be spotty.
What you want is a glibc version that is built with -gdwarf-2 and -O0. AFAIK, you'll have to get that by building glibc yourself from the source.
You'll probably have to run the configure script and select the -g and -O options for the build. Then, run make. The exact details should be in the source documentation [or online] somewhere.
Then, you'll have to [forcibly] link your program against the built-from-source version.

Resources