Git Product home page Git Product logo

debugir's Introduction

DebugIR: Debugging LLVM-IR Files

This utility revives the debug-ir pass in LLVM, but as a standalone tool. I found the idea of having a separate utility simpler after knowing that this earlier patch to revive it as a pass inside LLVM didn't go through.

Instructions

Let us assume that the LLVM-IR to be debugged is named hello.ll. Such a file can be dynamically generated, or using clang as

  • $clang -emit-llvm -o hello.ll -S hello.c.
hello.c
  #include <stdio.h>
  #include <string.h>

  int main(int argc, char *argv[])
  {
    if (!strcmp(argv[0], "hello")) {
      printf("Hello World\n");
    } else {
      printf("No hello\n");
    }
    return 0;
  } 

Clone and build

This tool requires LLVM-12 to be installed.

  • $git clone https://github.com/vaivaswatha/debugir.git debugir
  • $cd debugir; mkdir build; cd build
  • $cmake -DCMAKE_BUILD_TYPE=Release ../
  • $cmake --build .

If you have LLVM installed in a non-standard path, you may provide the additional CMake argument -DLLVM_DIR=/path/to/llvm.

Run

You should now have an executable file debugir in the build directory.

  • $./debugir hello.ll

This produces a file hello.dbg.ll. NOTE The utility also overwrites the input LLVM-IR file (if you have comments in it, they will be lost). The new file hello.dbg.ll is semantically the same as the input file, but with debug information referring to the input file.

If you now debug hello.dbg.ll (instead of debugging hello.ll), the debugger can pickup and display hello.ll as the execution proceeds.

Note: LLVM values that don't have an explicit name cannot have their names (and hence values) seen in GDB. To workaround this, provide explicit names yourself or run the instruction namer pass by providing the -instnamer flag to debugir.

Following on the example here let us try and debug hello.dbg.ll.

  • $gdb lli
  • (gdb) set args -jit-kind=mcjit hello.dbg.ll
  • (gdb) break hello.ll:25 # set breakpoint at line 25 in hello.ll
  • (gdb) run

You should now hit the program at line 25 in hello.ll, assuming that line 25 is a valid line number in the LLVM source. Change this line number to an appropriate value or to a function name. Note: Since lli, at the time of invocation from gdb will not have, yet, loaded the object file for hello, you will need to set set breakpoint pending on in gdb.

debugir's People

Contributors

arkham avatar manggoguy avatar vaivaswatha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.