I am writing an LLVM Function pass. I would like to call Loop Pass on each of Loops in the function. However I am not able to call a Loop Pass from Function Pass. When I add addRequired for required loop pass, it gives error that it can't schedule that pass.
Any workarounds?
I'm wondering if you want to run the LoopPass on every loop, then why don't you just invoke the loop pass normally via command line ? by the way it is possible to invoke a loop pass inside function pass. LoopPassManager is doing exactly what you want, it is a function pass which runs loops passes on every loop. so take a look at LPPassManager class in LoopPass.cpp and LoopPass.h
Related
How can I return multiple object from a mocked factory returning unique_ptr, when the calls cannot be identified through different input parameters to the called function?
I'm doing this:
EXPECT_CALL(MyFactoryMock, create())
.WillRepeatedly(Return(ByMove(std::make_unique<MyObjectTypeMock>())));
And run-time error is:
[ FATAL ]
/.../tools/googletest/1.8.0-57/include/gmock/gmock-actions.h:604::
Condition !performed_ failed. A ByMove() action should only be
performed once.
Doing the same thing only once, using WillOnce, works fine.
Follow-up question: Return multiple mock objects from a mocked factory function which returns std::unique_ptr
ByMove is designed to move a predefined value that you prepared in your test, so it can only be called once. If you need something else, you'll need to write it yourself explicitly.
Here's an excerpt from the googletest documentation:
Quiz time! What do you think will happen if a Return(ByMove(...))
action is performed more than once (e.g. you write ...
.WillRepeatedly(Return(ByMove(...)));)? Come think of it, after the
first time the action runs, the source value will be consumed (since
it’s a move-only value), so the next time around, there’s no value to
move from – you’ll get a run-time error that Return(ByMove(...)) can
only be run once.
If you need your mock method to do more than just moving a pre-defined
value, remember that you can always use a lambda or a callable object,
which can do pretty much anything you want:
EXPECT_CALL(mock_buzzer_, MakeBuzz("x"))
.WillRepeatedly([](StringPiece text) {
return MakeUnique<Buzz>(AccessLevel::kInternal);
});
EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x"));
EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x"));
Every time this EXPECT_CALL fires, a new unique_ptr<Buzz> will be
created and returned. You cannot do this with Return(ByMove(...)).
In Intel Pin you can get the return address of a routine call using IARG_RETURN_IP as one of the arguments of RTN_InsertCall.
I wanted to do the same with a system call, instrumented using PIN_AddSyscallEntryFunction and PIN_AddSyscallExitFunction.
So at first I thought about getting the value of the instruction pointer after the call using
ADDRINT returnIp = PIN_GetContextReg(ctx, REG_INST_PTR);in the function passed as argument to PIN_AddSyscallExitFunction.
However, I noticed that, if I get the value of REG_INST_POINTER in the same way but this time before the system call is executed, I always get the same two values for the instruction pointer.
For example, I would always get 2003266482 before and 2003266484 after.
So I was wondering why is this the case and if I am doing something wrong.
This has to do with the way system calls are executed in libc, there is a single assembly stub that actually does what needs to be done to pass control from and back to the kernel, which all system calls go through.
Is there a way to proceed execution in gdb until a function is called and then pause inside that function? It is a pain to use n and s for the code I am working with. I would much prefer a nextFrame and fin, assuming a nextFrame existed which took me into a new function. It would be extra cool if nextFrame could tell me when we only unwind the stack from the current scope, i.e. we do not make another function call, and then it could pause at the last line of the current scope.
Basically, I want to view my codebase from a callstack perspective and not from a line by line perspective.
P.S. Assuming such a facility exists, I would imagine it being problematic to use with boost. Eg. if I have a line like boost::shared_ptr<MyType> a = foo(); then it will pause first inside boost code, before it pauses inside foo(). This is a problem because I am not interested in the boost code and only want to see what is inside foo.
P.S. I also have clang. I wonder if this is possible in clang.
Use b function_name to apply the break point inside a function.
Your program in execution will pause at the entry of that function.
Alternatively You can also use
b filename:line_number to pause the execution of your program at the specific line in a file.
is it possible that gdb breaks when next function is pushed onto the stack. If yes, how ?
There could be situations when you dont know what is the next fn that would be called from current fn, for example, calling the next function using callback.
If the inferior is stopped and you want to step into the next function call, you can just step until you reach it.
If you want a way to say "please continue but stop when the next function is called" -- well, there is no built-in way to do that in gdb. If it's a real need, you could try to implement it in a couple of ways.
One way would be to use Python to automate the stepping. The idea is, call step until the newest frame changes.
Another way would be to try to set a watchpoint on the frame pointer. This only works if your code has frame pointers, though.
Say I am in A() and A() calls B(). I just entered A() and I want the program to run until I am in B(). It doesn't have to be a specific function B(). I just want my program to pause whenever it enters a new function. Is there a way to do that?
For calls, as mentioned at: List of all function calls made in an application :
set confirm off
rbreak .
rbreak sets a breakpoint for every function that matches a given regular expression, . matches all functions.
This command might take a while to run for a large executable with lots of functions. But once it finishes, runtime will be efficient.
The exit is trickier, since we can't know at compile time where we will land: How to set a breakpoint in GDB where the function returns?
At How to break on instruction with a specific opcode in GDB? I also provided a script that single steps until a desired instruction is found, which you could use to find callq. That one has the advantage of not making you wait on a large executable, but execution will be very slow, so the target can't be very far away.
There would be a nice solution in form of setting a breakpoint on call instruction, but as this answer states there is no way to do that.
I think, the easiest solution would be to set that breakpoints manually or try to write a script in Python which finds function calls in the currect function listing and sets desired breakpoints.