How to read lambdas in android / R8 stack trace de-obfuscated with retrace.jar? - stack-trace

Specifically, lines similar to:
<my-package>.-$$Lambda$<my-class>$TBpBoCodhQrLRrW-jmx762QZ0VY.run(Unknown Source:2)
<my-package> and <my-class> were obviously replaced.
Perhaps there are some options to R8 to preserve pertinent information?

The classes with names starting with -$$Lambda$ are generated by R8 (and D8) when desugaring Java lambdas. These are synthetic classes, and they have no corresponding item in the input program. Normally a -$$Lambda$ will not be on the top of stack, as they will always call the lambda$xxx method generated by javac which has references back to the original source.
If you are using retrace.jar from ProGuard, please make sure to use a recent version which supports inline frames in the mapping file. Version 6+ should work.

Related

Disable console output from the from the OPAL project?

I'm using the OPAL framework to implement static analyses. I wondered if it is possible to suppress the console output of the framework which is printed on the console while execution. The following shows a part of the output.
...
[info][OPAL] Bytecod Representation - Development Build (asserstions are enables)
[info][project configuration] the JDK is part of the analysis
[warn][project configuration] supertype information incomplete
...
I found that OPAL has several LogLevels (i.e. WARN, INFO, ERROR) but I couldn't find a way to specify the logging granularity. I'm really interested in warnings and errors but I would like to suppress the (massive) output at info level.
By now I figured out that it is possible to suppress the console output of OPAL. The OPAL logging mechanism uses several LogContext objects. It exists one GlobalLogContext and one LogContext per available Project. Since both are independent it is necessary to silence both types.
The first context is used for every logging event which does not happen in the context of a specific project whereas the project-specific context is used to log messages in a given context.
The OPALLogger.update(...) method can be used to update the Logger that is used for a LogContext. With this method, it is possible to associate a new Logger with a LogContext. If you are running OPAL with the command line, a ConsoleOPALLogger can be used as follows.
val project = ...
OPALLogger.updateLogger(project.logContext, new ConsoleOPALLogger(true, org.opalj.log.Error))
OPALLogger.updateLogger(GlobalLogContext, new ConsoleOPALLogger(true, org.opalj.log.Error))

some variables is inaccessible during debug

I am currently debugging custom library.
Moving deeper and deeper in calls I get to the external class (not mine libraries like jackson for example) where the values of the variables is not being displayed and I cannot print them using display tab either.
How to make them accessible?
When compile, you can control how much debugging information should be generated into the class files.
Choice Option Information generated in class
1 -g:none No debug information
2 -g:lines Line number only
3 -g:lines,source Line number & source file
4 (default) Same as #3
5 -g:lines,source,vars Line number, source file & variables
6 -g Same as #5
I doubt that the class files in the library compiled without variables information. If you have source code, build it by yourself with appropriate option to include the debugging information, like -g:lines,source,vars.

Print x86 assembly instead of getting machine code from ExecutionEngine

I've seen several conflicting descriptions of how to do this around the google results, and haven't been able to get any of them to work.
My problem is basically this: where I call ExecutionEngine::getPointerToFunction (with an llvm::Function*), I'd like to instead get the pretty-printed x86 assembly that would be produced for this function.
Anybody?
[ETA: I'm using LLVM 3.3. The descriptions I've found seem to be for earlier versions of LLVM.]
It turns out that you can add an event listener to a JIT ExecutionEngine with ExecutionEngine::RegisterJITEventListener. If you provide an instance of that class, you can have your callback invoked when machine code is generated for you, and you'll be given a pointer to the machine code and its length. With this, you can call llvm::sys::disassembleBuffer to get a description of the machine code buffer.
However, the llvm::sys::disassembleBuffer function just defers to the udis library if LLVM was compiled with that support. Since my build of LLVM didn't have this flag set and I can't rebuild it, I'll just look into using the udis library directly:
https://github.com/vmt/udis86

MS VS-2005 Compiler optimization not removing unused/unexecuted code

I have a workspace built using MS-Visual Studio 2005 with all C code.In that i see many functions which are not called but they are still compiled(they are not under any compile time macro to disable them from compiling).
I set following optimization settings for the MS-VS2005 project to remove that unused code:-
Optimization level - /Ox
Enable whole program optimization - /GL
I tried both Favor speed /Ot and Favor Size /Os
Inspite of all these options, when i see the linker generated map file, I see the symbols(unsed functions) names present in the map file.
Am I missing something? I want to completely remove the unused code.
How do I do this?
The compiler compiles C files one-at-a-time. Therefore, while compiling a C-file that does contains an unused function, the compiler cannot be sure that it will not be called from another file and hence it will compile that function too. However, if that function were declared as static (file-scope), then the compiler would know it is not used and hence remove it.
Even with whole program optimization, I think it would still not be done since the compilation could be for a library.
Linkers do something similar to what you are looking for. If your code links against a library containing multiple objects, then any objects that do not contain functions used by your code (directly or indirectly) would not be included in the final executable.
One option would be to separate your code into individual libraries and object files.
PS - This is just my guess. The behavior of the compiler (with whole program optimization) or linker essentially depends on the design choices of that particular compiler or linker
On our projects we have a flag set under the project properties\Linker\Refrences. We set it to Eliminate Unreferenced Data (/OPT:REF), according to the description this is supposed to remove function calls or data that are never used. I am just going by the description, I have never tested this or worked with it. But I just happened to see it within the last hour and figured it might be something you could try.

I get new javascript every GWT compile without changing java source

GWT compiles the Java source into Javascript, and names the files according to a hash of their contents. I'm getting a new set of files every compile, because the javascript contents are changing, even when I don't change the source at all.
The files are different for OBF and PRETTY output, but if I set it to DETAILED, they're no longer different every compile. In PRETTY, I can see that all/most of the differences between compiles are in the value parameters for typeId. For example, a funciton called initValues() is called with different values for it's typeId parameter.
In PRETTY mode, the differences you see are allocation of Java Classes to TypeIds. It's how GWT manages run time type checking. You'll notice a table at the bottom of each script essentially mapping each typeId to all compatible superclasses. This is how GWT can still throw ClassCastException in JavaScript (though you should run into this very rarely!).
In OBF mode, the differences are due to the allocation of minified function names.
In both cases, it's due to the order the compiler is processing the code. Some internal symbol tables might be using a non-ordered collection store symbols for processing. It can happen for lots of reasons.
As far as I know, GWT will compile a new version every time you compile it, this is a feature ;)
You can use ant to control it though, so that it only builds the GWT section of your application if it's actually changed:
http://wiki.shiftyjelly.com/index.php/GWT#Use_The_Power_of_Ant_to_Build_Changes_Only