-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
irutil: add utility API for creating dwarf metadata (was: Example with inclusion of DWARF output?) #86
Comments
Just checked the Users repos from the README, for potential example code that could be used:
No luck there. Any ideas? 😄 |
Hi Justin! Glad to see you are getting into experimenting with LLVM IR in Go :) The first principle of this how to extends beyond the scope of the The easiest way to get a feel for what the structure of the IR looks like, simply parse a sample LLVM IR assembly file containing the language constructs you'd like to produce. The step by step instructions would be roughly as follows:
Hope this helps! Cheers, AppendicesStep 1
|
Note, I am well aware that defining DWARF debug info in this way is very verbose. Sorry :) It is what we have currently. Most likely, users would want to write their own helper libraries for constructing metadata debug info. The IR package in its current form is mostly concerned with the in-memory representation of LLVM IR. Over time, we should evaluate the different approaches taken by the users of Feel free to report back if you play around with DWARF debug info construction and arrive at a clean API for the helper library! We'd be curious to see what it may look like. |
Oh, and for what it is worth, geode does include at least partial support for generating DWARF debug info. The following
|
Oh wow! That's fantastic @mewmew. This gives plenty of info on how to get up and running with it. Thanks heaps. 😁 Time to experiment... |
Glad to be of help :)
Happy hacking!! Oh, and if you'd like, please report back in a week or so and tell us what worked well and what didn't so we can learn, iterate and improve. @justinclift, once you've had more experience with this, would you be willing to create a mini-guide/howto for how to generate DWARF debug info using Cheerful regards, |
Yep, that sounds like a good idea. And it's my kind of thing to do as well. Will report back, and produce suitable guide kind of thing. 😁 |
From: llir/llvm#86 (comment) The .ll was generated using: $ go run main.go > foo.ll The .ll can be compiled to a Linux binary with: $ clang --target=x86_64-pc-linux-gnu -g -Wno-override-module -o foo foo.ll
As an early initial thought 😉, being able to set a default Align would be useful, so
Maybe something like?
I don't (yet) have enough understanding of how things hang together to create a useful PR. In theory that should come with time. 😉 |
It should be possible to string that together. However, currently, an That being said, I think this may be something for Edit: just to clarify, I think that it would make sense to extend the core IR API by adding a package ir
type Func struct {
Parent *Module
...
}
type Block struct {
Parent *Func
...
}
type InstFoo struct {
Parent *Block
...
} Edit2: Turns out Edit3: I think we have to decide whether to add a Parent field to each instruction or not. Also, if the |
No worries. Not personally going to put too much thinking time into it just yet, as I've just managed to put together some .ll which gets close to generating a valid Wasm file (almost runnable in Firefox). With some minor hammering into shape, Firefox was able to run it. So, for tomorrow I'll try and reverse that ll file for equivalent If I can get that working, that would be good... 😄 But, sleep calls atm... |
Sleep tight :) |
From the Step 2 code here: llir/llvm#86 (comment)
Is there a decent way to compare and display the differences between two .ll files? Started creating a basic command line util to do it, but hopefully there's existing (better) tooling that could be used? eg no need to spend time re-inventing wheels that already exist. 😄 |
Not pretty sure since I haven't tried it but maybe https://llvm.org/docs/CommandGuide/llvm-diff.html this can help? |
Thanks @dannypsnl, I'll have a go with that. 😄 |
Yep, that does seem to work. It operates on After manually renaming all instances of "foo" in a test .ll to "bar", then running
Looks like the right kind of thing. 😄 |
Apologies for the delay in getting back to this. I'll pick it up in a few days, as I'm just trying to get an initial wasm thing done first which makes use of the knowledge gained here. |
Hi Justin. No rush. Hack on it when you are in the mood! We will be here happy to look at what you've played with :) |
Marking this issue with the util milestone, as generating LLVM IR metadata using the |
According to IBM developer document
I don't think this is possible to handle by But I think, on the other hand, we could make a package under diFile := di.NewDIFile("foo.c", "where/am/i")
compileUnit := di.NewCompileUnit(diFile) // omit others fields
subProg := diFIle.SubProgram("foo")
subProg.Location(2, 13)
wow, err := subProg.Variable("wow")
if err != nil { // probably because undefined?
} And |
@dannypsnl, your idea for the So, in general we err on the side of putting things into |
This comment has been minimized.
This comment has been minimized.
Is there a
for every line would be nice also doing
would be useful. If the util API isn't ready yet, how would I do this with the current API? |
While messy and low-level, #86 (comment) details the API usage for adding DWARF debug info. Note, the easiest way to try this yourself is to simply generate LLVM IR from C using the Of course, the Cheers, |
Looking at the examples, would it be feasible to add one that includes the DWARF debugging info?
For example, the current "Output example - Produce LLVM IR assembly" is useful for getting people started.
Pretty much anyone wanting to make non-trivial applications though, will need to add debugging info to help with diagnosing problems in their compiled files.
Maybe a follow up example or two? 😄
The text was updated successfully, but these errors were encountered: