Skip to content

Commit

Permalink
#8357: Add option to include DWARF info in ELF files
Browse files Browse the repository at this point in the history
  • Loading branch information
ihamer-tt committed May 14, 2024
1 parent 8f969f9 commit b8994f7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ running such tests.
- Files with the kernel configurations will be automatically generated. For example: `built/0/kernels/kernel_args.csv`
- To examine the compile time arguments of a kernel:
- Within your kernel, assign the arguments to **constexpr** like this: `constexpr uint32_t in1_mcast_sender_noc_y = get_compile_time_arg_val(0);`
- Run `dump-constexprs.py` script on the generated ELF file. E.g. `python tt_metal/tools/dump-consts.py built/0/kernels/command_queue_producer/1129845549852061924/brisc/brisc.elf --function kernel_main`
- Run `dump-constexprs.py` script on the generated ELF file. E.g. `python tt_metal/tools/dump-consts.py built/0/kernels/command_queue_producer/1129845549852061924/brisc/brisc.elf --function kernel_main`. Note: debug information (DWARF) must be present in ELF files (compiler option `-g`). To enable, add TT_METAL_RISCV_DEBUG_INFO=1 environment variable.

### Tips for debugging hangs with watcher

Expand Down
5 changes: 5 additions & 0 deletions tt_metal/jit_build/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ void JitBuildEnv::init(uint32_t device_id, tt::ARCH arch)
break;
}
common_flags += "-std=c++17 -flto -ffast-math ";

if (tt::llrt::OptionsG.get_riscv_debug_info_enabled()) {
common_flags += "-g ";
}

this->cflags_ = common_flags;
this->cflags_ +=
"-fno-use-cxa-atexit -fno-exceptions "
Expand Down
3 changes: 3 additions & 0 deletions tt_metal/llrt/rtoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ RunTimeOptions::RunTimeOptions() {
if (clear_l1_enabled_str[0] == '0') clear_l1 = false;
if (clear_l1_enabled_str[0] == '1') clear_l1 = true;
}

const char *riscv_debug_info_enabled_str = std::getenv("TT_METAL_RISCV_DEBUG_INFO");
set_riscv_debug_info_enabled(riscv_debug_info_enabled_str != nullptr);
}

const std::string& RunTimeOptions::get_root_dir() {
Expand Down
6 changes: 6 additions & 0 deletions tt_metal/llrt/rtoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class RunTimeOptions {

bool clear_l1 = false;

bool riscv_debug_info_enabled = false;

public:
RunTimeOptions();

Expand Down Expand Up @@ -142,6 +144,10 @@ class RunTimeOptions {
inline bool get_clear_l1() { return clear_l1; }
inline void set_clear_l1(bool clear) { clear_l1 = clear; }

// Whether to compile with -g to include DWARF debug info in the binary.
inline bool get_riscv_debug_info_enabled() { return riscv_debug_info_enabled; }
inline void set_riscv_debug_info_enabled(bool enable) { riscv_debug_info_enabled = enable; }

private:
// Helper functions to parse DPrint-specific environment vaiables.
void ParseDPrintEnv();
Expand Down
4 changes: 3 additions & 1 deletion tt_metal/tools/dump-consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def main():
with open(elf_file_path, "rb") as f:
elffile = ELFFile(f)
if not elffile.has_dwarf_info():
print("ELF file has no DWARF info.")
print(
"ELF file has no DWARF info. To instruct the compiler to generate DWARF info, add TT_METAL_RISCV_DEBUG_INFO=1 to your environment."
)
return

dwarfinfo = elffile.get_dwarf_info()
Expand Down

0 comments on commit b8994f7

Please sign in to comment.