<div dir="auto">Hi Roland,<div dir="auto">Yes you are right I'm using 19.3.1. I'll upgrade when possible and try it.</div><div dir="auto"><br></div><div dir="auto">Atm I was able to create a maven project and create my own instrument tool. I'm just missing to understand why the ID I'm using as the new option is not available but I'll figure it out. I hope :)</div><div dir="auto"><br></div><div dir="auto">Thanks</div><div dir="auto">Alberto</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 12, 2020, 15:25 Roland Schatz <<a href="mailto:roland.schatz@oracle.com">roland.schatz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div>Hi Alberto,<br>
<br>
</div>
<div><br>
</div>
<div>On 2/12/20 2:52 PM, Alberto Barbaro
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hi Roland,
<div>I think that's exactly what I need. I was able to build
simpletool and to use Truffle so I'll adapt it to my need
using LLVMTruffleInstrument instead TruffleInsturment. Does it
sound correct to you?</div>
</div>
</blockquote>
<p><br>
I think either way is fine. It's probably a good idea to do your
own instrument, but you can start from the LLVMTracerInstrument,
because it already does something very similar to what you want to
do.<br>
</p>
<br>
<blockquote type="cite">
<div dir="ltr">
<div><br>
</div>
<div>In addition I tried lli with the experimental options but I
had the following errors:</div>
<div><br>
</div>
<div>[...]<br>
ERROR: java.lang.IllegalStateException: The registerService
method can only be called during the execution of the
Env.createContext method.<br>
org.graalvm.polyglot.PolyglotException:
java.lang.IllegalStateException: The registerService method
can only be called during the execution of the
Env.createContext method.<br>
at
com.oracle.truffle.api.TruffleLanguage$Env.registerService(TruffleLanguage.java:2382)<br>
at
com.oracle.truffle.llvm.instruments.trace.LLVMTracerInstrument.initialize(LLVMTracerInstrument.java:58)<br>
at
com.oracle.truffle.llvm.runtime.LLVMContext.initialize(LLVMContext.java:276)<br>
[...]<br>
</div>
</div>
</blockquote>
<p><br>
From the stack trace, looks like you're on version 19.3, right?
Then that is a known bug, it's already fixed on current master and
on the 20.0 release branch. You can use one of our dev builds
(<a href="https://urldefense.com/v3/__https://github.com/graalvm/graalvm-ce-dev-builds/releases__;!!GqivPVa7Brio!KtmDvDwsduFtVn0CVvmx-N5W6pyCELxOoelaa6j3OcnUAtlSD4yrlq6rD3V3zlwBniGUzA$" target="_blank" rel="noreferrer">https://github.com/graalvm/graalvm-ce-dev-builds/releases</a>) in the
meantime. It will also be fixed in the upcoming 20.0 release.<br>
<br>
<br>
- Roland<br>
<br>
<br>
</p>
<blockquote type="cite">
<div dir="ltr">
<div><br>
</div>
</div>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Il giorno mer 12 feb 2020 alle
ore 11:24 Roland Schatz <<a href="mailto:roland.schatz@oracle.com" target="_blank" rel="noreferrer">roland.schatz@oracle.com</a>> ha
scritto:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div>Hi Alberto,<br>
</div>
<div><br>
</div>
<div>On 2/11/20 6:40 PM, Alberto Barbaro wrote:<br>
</div>
<blockquote type="cite">
<div dir="auto">Hi Roland,
<div dir="auto">Yes you are right, that's the proper
class name.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Atm the goal for me is just to print all
the instructions that are executed In the LLVM IR firm
if possible.</div>
</div>
</blockquote>
<br>
The LLVMBitcodeInstructionVisitor is used just for parsing
the bitcode. For runtime instrumentation, there is the
Truffle instrumentation framework that might be better
suited for what you're trying to do:<br>
<a href="https://urldefense.com/v3/__https://www.graalvm.org/docs/graalvm-as-a-platform/implement-instrument/__;!!GqivPVa7Brio!M_VQB1VYM2oG0tUtVXzAs5zr9rDHleDIiNnN14WgTynkSubDpWG5C3J0oIZzg4DLWps$" target="_blank" rel="noreferrer">https://www.graalvm.org/docs/graalvm-as-a-platform/implement-instrument/</a><br>
<br>
We already have a few instruments that you might find
useful, either for using directly, or for building on top of
them.<br>
<br>
You can already get a trace of all executed bitcode
instructions:<br>
<blockquote type="cite">$ llvm-dis hello.bc<br>
$ lli --experimental-options --llvm.llDebug --llvm.traceIR
hello.bc<br>
[lli] >> Entering function @main at hello.ll:9:1
with arguments:[StackPointer 0x7f62b3fff010 (Bounds:
0x7f62aefff010 - 0x7f62b3fff010), 1, 0x55ad10a8ba48,
0x55ad10a8ba58]<br>
[lli] >> hello.ll:10:1 -> %1 = alloca i32,
align 4<br>
[lli] >> hello.ll:11:1 -> store i32 0, i32* %1,
align 4<br>
[lli] >> hello.ll:12:1 -> %2 = call i32 (i8*,
...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x
i8]* @.str, i32 0, i32 0)), !dbg !13<br>
Hello, World!<br>
[lli] >> hello.ll:13:1 -> ret i32 0, !dbg !14<br>
[lli] >> Leaving @main<br>
</blockquote>
<br>
The code for that is mainly in the classes
LLVMTracerInstrument and LLVMTraceNodeFactory. That might be
an easier entry point for what you're trying to do.<br>
<br>
<br>
<br>
We also have a code coverage tool:<br>
<a href="https://urldefense.com/v3/__https://www.graalvm.org/docs/reference-manual/tools/*code-coverage__;Iw!!GqivPVa7Brio!M_VQB1VYM2oG0tUtVXzAs5zr9rDHleDIiNnN14WgTynkSubDpWG5C3J0oIZzo_rD3k0$" target="_blank" rel="noreferrer">https://www.graalvm.org/docs/reference-manual/tools/#code-coverage</a><br>
<a href="https://urldefense.com/v3/__https://github.com/oracle/graal/tree/master/tools/src/com.oracle.truffle.tools.coverage/src/com/oracle/truffle/tools/coverage__;!!GqivPVa7Brio!M_VQB1VYM2oG0tUtVXzAs5zr9rDHleDIiNnN14WgTynkSubDpWG5C3J0oIZzHgM1A5U$" target="_blank" rel="noreferrer">https://github.com/oracle/graal/tree/master/tools/src/com.oracle.truffle.tools.coverage/src/com/oracle/truffle/tools/coverage</a><br>
<br>
If you run it with regular "lli --coverage ...", you'll get
C code covarage, but you can combine that with the
"--llvm.llDebug" option to get bitcode coverage, too (see
below for example output).<br>
<br>
<br>
I hope this helps,<br>
Roland<br>
<br>
<br>
<br>
<blockquote type="cite">$ lli --coverage
--coverage.Output=detailed --experimental-options
--llvm.llDebug hello.bc<br>
Hello, World!<br>
------------------------------------------------------------------------------------------<br>
Code coverage per line of code and what percent of each
element was covered during execution (per source)<br>
+ indicates the line is covered during execution<br>
- indicates the line is not covered during execution<br>
p indicates the line is part of a statement that was
incidentally covered during execution<br>
e.g. a not-taken branch of a covered if statement<br>
------------------------------------------------------------------------------------------<br>
Path |
Statements | Lines | Roots<br>
/home/roland/test/hello/hello.ll
| 100.00% | 100.00% | 100.00%<br>
<br>
; ModuleID = 'hello.bc'<br>
source_filename = "hello.c"<br>
target datalayout =
"e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
target triple = "x86_64-pc-linux-gnu"<br>
<br>
@.str = private unnamed_addr constant [15 x i8] c"Hello,
World!\0A\00", align 1<br>
<br>
; Function Attrs: noinline nounwind optnone sspstrong
uwtable<br>
define dso_local i32 @main() #0 !dbg !9 {<br>
+ %1 = alloca i32, align 4<br>
+ store i32 0, i32* %1, align 4<br>
+ %2 = call i32 (i8*, ...) @printf(i8* getelementptr
inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0)),
!dbg !13<br>
+ ret i32 0, !dbg !14<br>
}<br>
<br>
declare i32 @printf(i8*, ...) #1<br>
<br>
attributes #0 = { noinline nounwind optnone sspstrong
uwtable "correctly-rounded-divide-sqrt-fp-math"="false"
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"min-legal-vector-width"="0"
"no-frame-pointer-elim"="true"
"no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false"
"no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false"
"no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }<br>
attributes #1 = {
"correctly-rounded-divide-sqrt-fp-math"="false"
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true"
"no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false"
"no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false"
"no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }<br>
<br>
!<a href="https://urldefense.com/v3/__http://llvm.dbg.cu__;!!GqivPVa7Brio!M_VQB1VYM2oG0tUtVXzAs5zr9rDHleDIiNnN14WgTynkSubDpWG5C3J0oIZzO4ag0HM$" target="_blank" rel="noreferrer">llvm.dbg.cu</a> =
!{!0}<br>
!llvm.module.flags = !{!3, !4, !5, !6, !7}<br>
!llvm.ident = !{!8}<br>
<br>
!0 = distinct !DICompileUnit(language: DW_LANG_C99,
file: !1, producer: "clang version 8.0.1
(tags/RELEASE_801/final)", isOptimized: false,
runtimeVersion: 0, emissionKind: FullDebug, enums: !2,
nameTableKind: None)<br>
!1 = !DIFile(filename: "hello.c", directory:
"/home/roland/test/hello")<br>
!2 = !{}<br>
!3 = !{i32 2, !"Dwarf Version", i32 4}<br>
!4 = !{i32 2, !"Debug Info Version", i32 3}<br>
!5 = !{i32 1, !"wchar_size", i32 4}<br>
!6 = !{i32 7, !"PIC Level", i32 2}<br>
!7 = !{i32 7, !"PIE Level", i32 2}<br>
!8 = !{!"clang version 8.0.1 (tags/RELEASE_801/final)"}<br>
!9 = distinct !DISubprogram(name: "main", scope: !1,
file: !1, line: 3, type: !10, scopeLine: 3, spFlags:
DISPFlagDefinition, unit: !0, retainedNodes: !2)<br>
!10 = !DISubroutineType(types: !11)<br>
!11 = !{!12}<br>
!12 = !DIBasicType(name: "int", size: 32, encoding:
DW_ATE_signed)<br>
!13 = !DILocation(line: 4, column: 5, scope: !9)<br>
!14 = !DILocation(line: 5, column: 5, scope: !9)<br>
------------------------------------------------------------------------------------------<br>
Path |
Statements | Lines | Roots<br>
com.oracle.truffle.llvm.libraries.bitcode/src/crt0.c
| 100.00% | | 100.00%<br>
<br>
NO CONTENT AVAILABLE<br>
------------------------------------------------------------------------------------------<br>
Path |
Statements | Lines | Roots<br>
com.oracle.truffle.llvm.libraries.bitcode/src/exit.c
| 87.50% | | 100.00%<br>
<br>
NO CONTENT AVAILABLE<br>
------------------------------------------------------------------------------------------<br>
</blockquote>
<br>
<blockquote type="cite">$ lli --coverage
--coverage.Output=detailed hello.bc<br>
Hello, World!<br>
------------------------------------------------------------------------------------------<br>
Code coverage per line of code and what percent of each
element was covered during execution (per source)<br>
+ indicates the line is covered during execution<br>
- indicates the line is not covered during execution<br>
p indicates the line is part of a statement that was
incidentally covered during execution<br>
e.g. a not-taken branch of a covered if statement<br>
------------------------------------------------------------------------------------------<br>
Path |
Statements | Lines | Roots<br>
/home/roland/test/hello/hello.c
| 100.00% | 100.00% | 100.00%<br>
<br>
#include <stdio.h><br>
<br>
int main() {<br>
+ printf("Hello, World!\n");<br>
+ return 0;<br>
}<br>
------------------------------------------------------------------------------------------<br>
Path |
Statements | Lines | Roots<br>
com.oracle.truffle.llvm.libraries.bitcode/src/crt0.c
| 100.00% | | 100.00%<br>
<br>
NO CONTENT AVAILABLE<br>
------------------------------------------------------------------------------------------<br>
Path |
Statements | Lines | Roots<br>
com.oracle.truffle.llvm.libraries.bitcode/src/exit.c
| 87.50% | | 100.00%<br>
<br>
NO CONTENT AVAILABLE<br>
------------------------------------------------------------------------------------------<br>
</blockquote>
<br>
<br>
<blockquote type="cite">
<div dir="auto">
<div dir="auto"><br>
</div>
<div dir="auto">If all goes well I'd like to work on a
code coverage tool for the bitcode.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Thanks</div>
<div dir="auto">Alberto</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Feb 11, 2020,
16:02 Roland Schatz <<a href="mailto:roland.schatz@oracle.com" target="_blank" rel="noreferrer">roland.schatz@oracle.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div>Hi Alberto!<br>
<br>
I assume you mean the
LLVMBitcodeInstructionVisitor class, right? This
class is part of the internal implementation of
the LLVM runtime in GraalVM, and not meant to be
extended or used outside of the LLVM runtime. This
is not meant as API, we might change that class
without notice, even in minor releases.<br>
<br>
What are you trying to achieve by subclassing it?<br>
<br>
- Roland<br>
<br>
On 2/11/20 4:31 PM, Alberto Barbaro wrote:<br>
</div>
<blockquote type="cite">
<div dir="auto">Hi all,
<div dir="auto">I've just started to use graalvm
and I've noticed that the LLVMBitcodeVisitor
class is market as final. I'd like to create
my own visitor extending it... So I was
wondering if there is a better approach rather
then modifying a bit the source code. How
would you recommend to do it?</div>
<div dir="auto"><br>
</div>
<div dir="auto">Thanks</div>
<div dir="auto">Alberto</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
GraalVM-Users mailing list
<a href="mailto:GraalVM-Users@oss.oracle.com" rel="noreferrer noreferrer" target="_blank">GraalVM-Users@oss.oracle.com</a>
<a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></pre>
</blockquote>
<p><br>
</p>
</div>
_______________________________________________<br>
GraalVM-Users mailing list<br>
<a href="mailto:GraalVM-Users@oss.oracle.com" rel="noreferrer noreferrer" target="_blank">GraalVM-Users@oss.oracle.com</a><br>
<a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer noreferrer noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></blockquote>
</div>
</blockquote>
<p><br>
</p>
</div>
_______________________________________________<br>
GraalVM-Users mailing list<br>
<a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank" rel="noreferrer">GraalVM-Users@oss.oracle.com</a><br>
<a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></blockquote>
</div>
</blockquote>
<p><br>
</p>
</div>
</blockquote></div>