I'm trying to write a LLVM function pass to do some instrumentation.
Therefore, I I need to get
filename in which the function is declared
the line numbers (begin and end) of the source file in which the function is decalred.
I already found and tried getMetadata("dbg") but I do not want to use the compiler flag -g.
Is there another way to get these information?
Well... the debug metadata is emitted when debug info generation is enabled. You may want to reduce the amount of debug information generated with -gline-tables-only
Related
I am trying to collect some information from my LLVM optimization pass during runtime. In other words, I want to know the physical address of a specific IR instruction after compilation. So my idea is to convert the LLVM metadata into LLVM DWARF data that can be used during runtime. Instead of attaching the filename and line numbers, I want to attach my own information. My question falls into two parts:
Here is a code that can get the Filename and Line number of an instruction:
if (DILocation *Loc = I->getDebugLoc()) { // Here I is an LLVM instruction
unsigned Line = Loc->getLine();
StringRef File = Loc->getFilename();
StringRef Dir = Loc->getDirectory();
bool ImplicitCode = Loc->isImplicitCode();
}
But How can I set this fields? I could not find a relevant function.
How can I see the updated Debug Information during (filename and line numbers) runtime? I used -g for compiling but still I do not see the Debug Information.
Thanks
The function you need it setDebugLoc() and the info is only included in the result if you include enough of it. The module verifier will tell you what you're missing. These two lines might also be what's tripping you up.
module->addModuleFlag(Module::Warning, "Dwarf Version", dwarf::DWARF_VERSION);
module->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION);
I'm debugging an app with GDB and when I step into a frame, I see something like this:
#2 0x00007fff4da4276b in MHWRender::THgeometryOverrideEvaluator::doDGBoundingBox(TdgContext const&, OGSMayaCompoundNode*) ()
Normally, I'd just print out parameter addresses, but in the case of the second parameter here, there's no parameter name. How do I get the info I need?
How do I get the info I need?
The output you got is indicative of the code being compiled without debug info.
The easiest fix is to add -g as appropriate and rebuild your application.
Without debug info, you can only do debugging at assembly level, which requires knowing the calling convention on your platform (which you did not specify).
Assuming this is Linux on x86_64, and assuming that doDGBoundingBox is not a static function, the first (this) parameter will be passed in $rdi, second (the TdgContext&) in $rsi, and third (the OGSMayaCompoundNode*) in $rdx. Reference.
I have some proto definitions that i want to compile to C++ headers/code. When i do, all the data types are MessageLite, which I understand is more light weight for resource constraint devices.
However, MessageLite is missing a bunch of functions that i need (eg: MessageToJsonString and SerializeToOsStream). Is there a way for protoc to generate Message instead of MessageLite?
Alternatively, is there a better way to work with MessageLite? Namely, debugging and serializing to file?
Look in your protobuf definition for the following line:
option optimize_for = LITE_RUNTIME;
and either comment it out, or remove it. That line is instructing protoc to use MessageLite, not Message.
I am using MinGW (GCC) as a C++ compiler within my application. I have set it to redirect the output of its command line process to my app. Now, suppose I have the following simple C++ code:
int n = 5;
if (n == 6) cout << "YES";
else cout << "NO";
Is there a way to tell what line(s) of code were actually hit during execution of the application? Is there a command I can send to MinGW (GCC) process which, for the given example, would output 1 and 3, as those were the lines hit. And also, in case of a line inside a "for" loop, to tell how many times that statement was actually hit?
And, if not possible, what would be the best approach to having this information? Developing my own compiler or...? Thanks in advance
EDIT: Can someone provide a snippet of commands (in Windows) to be used in order to create a coverage-enabled GCC exe file?
"Is there a way to tell what line(s) of code were actually hit during execution of the application?"
Yes. It's an intrinsic GCC feature. You'll need to compile and link your code with the --coverage, -lgcov or -fprofile-arcs options set.
The gcov tool can be used to consolidate and interpret the actual informations gathered during program runs, that were instrumented with --coverage.
A very good tool to produce browsable consolidated and fairly visualized covearage information from gcov outputs is lcov.
Since you're using mingw you should be able to use gcov: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html
I just get started with LLVM. I am reading the code for stack protection which is located in lib/CodeGen/StackProtector.cpp. In this file, the InsertStackProtectors function will insert a call to llvm.stackprotect to the code:
// entry:
// StackGuardSlot = alloca i8*
// StackGuard = load __stack_chk_guard
// call void #llvm.stackprotect.create(StackGuard, StackGuardSlot)
// ...(Skip some lines)
CallInst::
Create(Intrinsic::getDeclaration(M, Intrinsic::stackprotector),
Args, "", InsPt);
This llvm.strackprotect(http://llvm.org/docs/LangRef.html#llvm-stackprotector-intrinsic) seems to be an intrinsic function of llvm, so I tried to find the source code of this function. However, I cannot find it...
I do find one line definition of this function in include/llvm/IR/Intrinsics.td, but it does not tell how it is implemented.
So my questions are:
Where can I find the code for this llvm.strackprotect function?
What is the purpose of these *.td files?
Thank you very much!
The .td file is LLVM's use of code-generation to reduce the amount of boilerplate code. In this particular case, ./include/llvm/IR/Intrinsics.gen is generated in the build directory and contains code describing the intrinsics specified in the .td file.
As for stackprotector, there's a bunch of code in the backend for handling it. See for instance lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp - in SelectionDAGBuilder::visitIntrinsicCall it generates the actual DAG nodes that implement this intrinsic