Hi I am trying to create some sort of a debugger that looks at system calls to detect them, but from an usability standpoint I wish to be able to get the source code name and line number where the error is detected. I have been using library called libunwind, but it gives me function name, offset from the function, and program counter in the address space of the executable. However, if you look at valgrind or gdb, it gives you the line number and the source code name when it was compiled with -g flag. How can I do it?
source code name and line number of the remote process
768 Views Asked by Yuta Nakamura At
2
There are 2 best solutions below
0
Erwan Legrand
On
Unfortunately, libunwind is only good at fetching addresses from the call stack. The library you are looking for is libbacktrace by Ian Lance Taylor.
It parses DWARF debugging information. As a result, it is able to generate a backtrace with the names of inlined functions, source file names and line numbers.
Edit: another option is backward-cpp. I have no experience with this one, though, while I can certify that libbacktrace rocks!
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in GDB
- crash utility itself crashes while decoding kdump generated from null pointer dereference in kernel module
- How to compile the Linux kernel with -O0 for more detailed debug?
- Can GDB call user-defined signal handler and still break on the code which threw a signal?
- Executable under GDB invokes different embedded Python
- GDB or GDB-oneAPI freezing when displaying complex variables in VSCode
- gdb: incorrect exit code
- Assembly, gdb duplicate names
- Don't pause GDB on child process exit
- Breakpoints for assembly code in VSCode with GDB
- Why is there a difference in memory writes when my qemu runs directly and when debugging the img with GDB?
- Shell execution buffer overflow server directly hosted
- How to set breakpoints in Visual Studio Code for debugging kernel code running in QEMU?
- Retrieving Exit Code from a Program Run with GDB in GitLab CI/CD Pipeline
- How to resolve the shared library of a function in core file, using GDB - when no symbols are loaded?
- GDB 'gef>' spam when using `layout asm`
Related Questions in PTRACE
- How to know if a syscall returned an error?
- Setup a watchpoint/breakpoint over a range of addresses with ptrace
- Problems with finding out file path via descriptor
- Trace all threads of a non-child process reliably and transparently with ptrace
- Does tgkill interrupt tasks currently executing a system call, effectively aborting it like ptrace does?
- PTRACE_GETSIGINFO si_code for breakpoint doesn't match with siginfo.h definition
- How to resume main thread/process while tracing syscalls and cloned process with ptrace()
- Reading a process' memory using ptrace but with restrictions
- GDB crashes debugging x86 binary under Rosetta 2 + Apple Virtualization Framework
- How do I monitor a specific process file read/writes on android?
- How do I test that a given shell has been executed in Python?
- ptrace not recording forked process despite setting PTRACE_SETOPTIONS to PTRACE_O_TRACEFORK
- How to solve "ptrace operation not permitted"?
- Is there a way to be able to quickly differentiate between a SIGTRAP caused by a breakpoint or a sigtrap caused by PTRACE?
- is it possible to use the ptrace to simulate the IO error on the specific lba range when running the FIO/Vdbench on the block device
Related Questions in DWARF
- How to compile the Linux kernel with -O0 for more detailed debug?
- Display source code with disassembly when path has changed
- BFD: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information
- Two seemingly different functions with same name exist in the C program (using DWARF info), why?
- where can I find an example of dwarf type units? (DW_AT_type_unit)
- gdb print and examine commands give incorrect results for a float variable
- Source code in memory rather than file for GDB
- Handling DWARF-5 relocations in a custom ELF loader
- Issue in parsing dwarf .debug_info section in an elf file
- DWARF line number data for simple AVR program (produced by GCC) doesn't seem right
- How to find the function DIE (Debugging Information Entry) using libdw, given an eip (instruction pointer)?
- Is it possible to encode DWARF debug information into wat (wasm textual format)?
- No source available for "Reset_Handler() at 0x8984" while debugging an ARM TrustZone Project in Renesas e2 Studio and embOS Library
- DWARF register numbers on MIPS
- Understanding objdump DWARF information regarding struct and its member variables
Related Questions in LIBUNWIND
- libunwind cannot resolve symbol names
- set_terminate unexplained behaviour with exception thrown from std::thread and libunwind
- libunwind: undefined reference to `_Ux86_64_getcontext' when compiling on Debian bullseye
- Baremetal Cortex-M7 gcc and unwind tables without libunwind
- Debian bookworm: Use both libunwind8 and libunwind-14?
- Exception Handling in C++ Implementation: What is the "alternative function entry point", entered by the unwinding library to destruct local objects?
- How to properly build & link the libunwind library
- Is llvm-libunwind safe to call from signal handler?
- Cross-compiling libunwind results in a missing shared library
- Build LLVM 16 (master) fail on libunwind
- How to reduce the overhead of libunwind
- could not dump fully backtrace with libunwind
- How to check if a pre-compiled libtcmalloc.so is compiled without libunwind?
- moviepy libunwind: pc not in table, pc=0xFFFFFFFFFFFFFFFF
- Why does cmp instruction cost too much time?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
For interactive viewing, you can use the
addr2linecommand line utility. It takes the executable name and the address (the program counter), and outputs the source file and line. If you create a programmatic parser, you can use that to check yourself.For resolving the address to a line from a program, you'd have to parse the DWARF information in the executable, specifically the line number section. From a cursory look at the
libunwindAPI, it doesn't seem like it supports retrieving that kind of information. There's another library calledlibdwarfthat supports general purpose DWARF parsing. It would be quite an involved project though, the way line numbers are stored in DWARF is not straightforward.If you don't want to go all the way with
libdwarf, you can use thereadelf --debug-dump=decodedlinecommand line to translate the line number section into a (relatively) easy to parse text file, and parse/interpret that from your C program. It will give you the correspondence between program counter values (ranges) and source line numbers.Another way to dump the line info from the command line is
dwarfdump -l. That one is more low level IIRC.Keep in mind inlined functions. The same PC value may correspond to more than one source line.
To see the DWARF information in an executable interactively, you can use the DWARF Explorer GUI tool (full disclosure: I wrote the GUI). The line numbers will be under the top item of a source file, under
stmt_list. The DWARF parser behind that tool is a Python one, not a C one.