Files
clang-p2996/llvm/test/tools/llvm-dwarfdump/debug-str.yaml
Xing GUO 67ce11405b [llvm-dwarfdump] Warn user when it encounters no null terminated strings.
When llvm-dwarfdump encounters no null terminated strings, we should
warn user about it rather than ignore it and print nothing.

Before this patch, when llvm-dwarfdump dumps a .debug_str section whose
content is "abc", it prints:

```
.debug_str contents:
```

After this patch:

```
.debug_str contents:
warning: no null terminated string at offset 0x0
```

Reviewed By: jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D86998
2020-09-03 08:49:57 +08:00

60 lines
1.9 KiB
YAML

## a) Show that llvm-dwarfdump dumps the .debug_str and
## .debug_str.dwo sections when --debug-str is specified.
## "some string\0foo\0\0"
# RUN: yaml2obj -DCONTENT="736f6d6520737472696e6700666f6f0000" %s -o %t.o
# RUN: llvm-dwarfdump %t.o --debug-str | FileCheck %s
# CHECK: .debug_str contents:
# CHECK-NEXT: 0x00000000: "some string"
# CHECK-NEXT: 0x0000000c: "foo"
# CHECK-NEXT: 0x00000010: ""
# CHECK: .debug_str.dwo contents:
# CHECK-NEXT: 0x00000000: "some string"
# CHECK-NEXT: 0x0000000c: "foo"
# CHECK-NEXT: 0x00000010: ""
# CHECK-EMPTY:
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .debug_str
Type: SHT_PROGBITS
Content: [[CONTENT]]
- Name: .debug_str.dwo
Type: SHT_PROGBITS
Content: [[CONTENT]]
## b) Test how we dump unprintable chars.
## ['\t', '\0', '\001', '\0', '\\', '0', '0', '1', '\0']
# RUN: yaml2obj -DCONTENT="090001005C30303100" %s -o %t2.o
# RUN: llvm-dwarfdump --debug-str %t2.o | FileCheck %s --check-prefix=ESCAPED
# ESCAPED: .debug_str contents:
# ESCAPED-NEXT: 0x00000000: "\t"
# ESCAPED-NEXT: 0x00000002: "\001"
# ESCAPED-NEXT: 0x00000004: "\\001"
# ESCAPED: .debug_str.dwo contents:
# ESCAPED-NEXT: 0x00000000: "\t"
# ESCAPED-NEXT: 0x00000002: "\001"
# ESCAPED-NEXT: 0x00000004: "\\001"
# ESCAPED-EMPTY:
## c) Test that llvm-dwarfdump emits a warning when it encounters a string without a null terminator.
## "abc\0" "abc"
# RUN: yaml2obj -DCONTENT="61626300616263" %s -o %t3.o
# RUN: llvm-dwarfdump --debug-str %t3.o 2>&1 | FileCheck %s --check-prefix=WARN
# WARN: .debug_str contents:
# WARN-NEXT: 0x00000000: "abc"
# WARN-NEXT: warning: no null terminated string at offset 0x4
# WARN: .debug_str.dwo contents:
# WARN-NEXT: 0x00000000: "abc"
# WARN-NEXT: warning: no null terminated string at offset 0x4