Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux (64-bit), nasm and gdb

Tags:

linux

gdb

nasm

I was searching other threads without luck. My problem is perhaps simple but frustrating. I'm compiling two files on 64-bit Ubuntu 11.04:

  1. nasm -f elf64 -g file64.asm
  2. gcc -g -o file file.c file64.o

Then I debug the resulting executables with gdb. With C, everything is OK. However, when debugging assembly, the source code is "not visible" to the debugger. I'm getting the following output:

(gdb) step
Single stepping until exit from function line,
which has no line number information.
0x0000000000400962 in convert ()

A quick investigation with:

objdump --source file64.o

shows that the assembly source code (and line information) is contained in the file.

Why can't I see it in a debug session? What am I doing wrong? These problems arose after moving to 64-bit Ubuntu. In the 32-bit Linux it worked (as it should).

like image 876
Bogdan Avatar asked Sep 18 '11 19:09

Bogdan


People also ask

What is Linux GDB?

GNU Debugger, also known as gdb, allows us to sneak through the code while it executes or what a program was trying to do at the moment before it crashed. GDB basically helps us to do four main things to catch flaws in the source code. Start the program, specifying arguments that may affect the general behavior.

Does Ubuntu have GDB?

There are three ways to install gdb on Ubuntu 20.04. We can use apt-get , apt and aptitude . In the following sections we will describe each method. You can choose one of them.

Does GDB work on assembly?

gdb is the GNU source-level debugger that is standard on linux (and many other unix) systems. It can be used both for programs written in high-level languages like C and C++ and for assembly code programs; this document concentrates on the latter.

Does clang work with GDB?

You can use GDB or lldb with clang.


1 Answers

With NASM, I've had much better experience in gdb when using the dwarf debugging format. gdb then treats the assembly source as if it were any other language (i.e., no disassemble commands necessary)

nasm -f elf64 -g -F dwarf file64.asm

(Versions 2.03.01 and later automatically enable -g if -F is specified.)

I'm using NASM version 2.10.07. I'm not sure if that makes a difference or not.

like image 86
Mike Hobbs Avatar answered Nov 14 '22 22:11

Mike Hobbs