在NASM中调试符号更多

问题描述

在StackOverflow上已经多次询问了此问题,但我尝试了所有答案,但仍无法使NASM包含DWARF调试符号。

我正在Ubuntu 18.04 64位下使用NASM 2.13.02。我不确定我是否仍然缺少什么?

万一重要,我实际上想同时使用LLDB和GDB。

谢谢。

这是我的代码

class GuidFlavoring<FlavorT> {
  // tslint:disable-next-line: variable-name
  _type?: FlavorT;
}

/** A **guid** type,based on **string** */
type GuidFlavor<T,FlavorT> = T & GuidFlavoring<FlavorT>;

/** A **guid**-flavored string primitive,supported by factory methods in the **Guid** class
 */
export type guid = GuidFlavor<string,'guid'>;

/** A container for factory methods,which support the **guid** type */
export class Guid {
  /** Specifies the RegExp necessary to validate **guid** values */
  private static validator: RegExp = new RegExp(
    '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$','i'
  );

  /** Generates a random,hyphenated **guid** value */
  static newGuid = (): guid =>
    [
      Guid.generateGuidSegment(2),Guid.generateGuidSegment(1),Guid.generateGuidSegment(3),].join('-');

  /** Generates a new **guid**,with the empty/least possible value
   * @returns {guid} 00000000-0000-0000-0000-000000000000
   */
  static empty = (): guid => '00000000-0000-0000-0000-000000000000';

  /** Generates a new **guid**,with the full/greatest possible value
   * @returns {guid} ffffffff-ffff-ffff-ffffffffffff
   */
  static full = (): guid => 'ffffffff-ffff-ffff-ffffffffffff';

  /** Evaluates whether the supplied **guid** is equal to the empty/least possible value */
  static isEmpty = (value: guid) => value === Guid.empty();

  /** Evaluates whether the supplied *guid* is equal to the empty/greatest possible value */
  static isFull = (value: guid) => value === Guid.full();

  /** Evaluates whether the supplied value is a valid **guid** */
  static isValid = (value: string | guid): boolean =>
    Guid.validator.test(value);

  /** Generates a specified number of double-byte segements for **guid** generation  */
  private static generateGuidSegment(count: number): string {
    let out = '';
    for (let i = 0; i < count; i++) {
      // tslint:disable-next-line:no-bitwise
      out += (((1 + Math.random()) * 0x10000) | 0)
        .toString(16)
        .substring(1)
        .toLowerCase();
    }
    return out;
  }
}

这是我建立和链接的方式:

section .bss
section .text

global _start

_start:
    mov ebx,0
    mov eax,1
    int 80h

结果文件为:

nasm -g -F dwarf -f elf64 hello.asm
ld -s -o hello hello.o

尝试检查是否包含DWARF数据:

$ ls -la hello
-rwxr-xr-x 1 terry terry 352 Sep  4 18:21 hello
$

在gdb下运行它:

$ dwarfdump hello
No DWARF @R_345_4045@ion present in hello
$

解决方法

我是根据@Michael Petch的建议自我回答自己的问题,他是真正找到根本原因的人。

问题是我将ld-s一起使用,这意味着“全部剥离”,包括调试符号,即我正在破坏自己的努力。

正确的命令应该是:

nasm -g -F dwarf -f elf64 hello.asm
ld -o hello hello.o

现在,使用gdb:

$ gdb ./hello 
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
[.. snip copyright ..]
Reading symbols from ./hello...done.

(gdb) b _start
Breakpoint 1 at 0x400080: file hello.asm,line 7.

(gdb) run
Starting program: /home/terry/hello 

Breakpoint 1,_start () at hello.asm:7
7       xor ebx,0
(gdb) 
$