Getting started with Intel Processor Trace (Intel PT) [closed] - debugging

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 months ago.
Improve this question
I have gone through Chapter 36 of "Intel® 64 and IA-32 Architectures
Software Developer’s Manual, Volume 3 (3A, 3B & 3C): System Programming Guide" and could understand the capabilities/features of Intel PT. However, I could not get information on how to use it. If I want to start capturing a trace, how should I proceed and where can I configure options that I am interested in? Any pointer to such information will be of great help. Once I have this information, I can follow above mentioned chapter 36 to perform analysis over the captured trace.

You can do it with Linux kernel 4.3, and these are the patch that goes in:
https://lkml.org/lkml/2013/12/11/233
https://lkml.org/lkml/2015/9/24/181
https://lkml.org/lkml/2015/9/27/45
This is on the interaction of PT with other Intel features like LBT:
https://lkml.org/lkml/2014/7/31/572
Read up the documentation at tools/perf/Documentation/intel-pt.txt on usage how to.
Andi Kleen from Intel is the originator of the patch for Skylakes/Broadwell (only these two processor support Intel PT), and he has the userspace tool for demonstrating its use for debugging:
https://github.com/andikleen/simple-pt
For example, the following are two different usage based on the tools above:
"sptcmd -c tcall taskset -c 0 ./tcall"
"sptdecode --sideband ptout.sideband --pt ptout.0".

The solution to your question consists of two distinct parts: First, you need to configure the processor of your system to start collecting the Processor Trace information and then dump that data into a file that can be processed later. Second, you need the tool that can make sense of the contents of that file.
The first question that has to be answered is: what OS are you running? The code that performs the processor configuration and data collection is going to need to run at the system/kernel level, so you will have to either be comfortable writing drivers for that space, or be able to find something that already does the job.
As mentioned above, the Linux kernel has built-in support for Processor Trace starting with the 4.1 kernel, incorporated into the perf facility. A few well worded searches should be all you need to take advantage of that.
For earlier versions of Linux, there is the simple-pt kernel module described above and found at: https://github.com/andikleen/simple-pt
This module can be made to work back to at least there 3.0 kernel, and is fairly straightforward to add. It also represents a good starting point if you want to port to a different operating system altogether, as it gives you an example of how to get the processor to do the right tricks to gather the data.
The library also has user-space utilities that are used to configure and control the simple-pt kernel module, as we as tools to decode the output of the module. Again, these can serve as starting points for your own projects if you need to move to a different OS. Note that these utilities require the Intel trace decoder library (libipt): https://github.com/01org/processor-trace.
Also note that the versions of simple-pt and libipt are not in sync. The latest simple-pt depends on an in-between releases version of libipt in order to build correctly.

For Linux there is also the kernel perf wiki https://perf.wiki.kernel.org and in particular for Intel PT there is page https://perf.wiki.kernel.org/index.php/Perf_tools_support_for_Intel%C2%AE_Processor_Trace

Related

Is GCC being replaced by LLVM? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I wonder whether LLVM by virtue of its newer design is to replace GCC in the open-source world?
LLVM should feature several techniques of inspecting code, so that IDE's are easier to program etc. However, GCC should still be good in terms of performance.
Short answer: No. They're both widely used depending on the context.
Long answer:
Depends, it's a matter of adoption as well as other factors.
For example, Apple uses LLVM (and Clang) for pretty much everything including building the kernel (previously built using GCC), bootloader and the userspace. As well as that, LLVM is used in the graphics drivers for compiling shaders to SGX USSE bytestreams, though here it's largely a case of eating your own dogfood.
As well as that, LLVM is also used in open source projects, for example in Mesa and in the Dolphin Emulator for JIT compilation.
Aside from that, GCC still has predominant usage, for example, Linux is built using GCC and while there have been attempts to build Linux using Clang+LLVM, they were more of an experiement than anything. As well as that, in the embedded world, a lot of embedded applications (for example, UBoot and Little Kernel) rely on features provided by GCC extensions and outright won't build with Clang+LLVM failing either at compilation to objects or linking stages.
For userspace applications however, it's largely a matter of personal (or your company's preference) since both of them offer roughly the same feature set including stuff like SIMD support and full support for C++14 and C11 (though GCC has some annoying unresolved bugs when it comes to C++ support, for example, Bug 61636).
The code inspection techniques are largely provided by Clang and in my personal experience provided a substantial amount of overhead (for example in Qt Creator and less so in XCode).

Types of assembly language [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I´m looking forward to learn an assembly language.
I searched web for the tutorial and found different tutorials with different syntax of assembly.
There is any difference between 8086 assembler, nasm and gcc?
What is the better way to learn code with in assembly language?
thanks.
Basically there are two flavours on the x86 chipset which is AT&T or the Intel snytax. Most people I know prefer the Intel syntax because it is much easier to understand, but of course this is also a matter of getting used to. When I learned assembly on 6510 or M68000 I found the AT&T syntax closer related, it is rather confusing with it's adressing modes IMO.
If you instruct gcc to write the assembly sourcefile it uses AT&T syntax by default, but you can switch that to Intel as well using
gcc -S -masm=intel test.c
nasm is an assembler and gcc is a compiler so they have quite different purposes.
As for learning assembly there are lots of tutorials, for example The Art of Assembly. But if you really want to learn it, IMO the best way is to start debug and enter some instructions and see what they are doing and how they change reigsters and flags, writing small loops first.
This way you can focus on the instructions and not fight with the assembler source syntax as well.
I wouldnt start with x86, not a good first instruction set even if you have the hardware. ARM, msp430, avr, and some others are better and have open source simulators where you can get better visibility. I would start small, simply adding or anding a few numbers, write a memory location, read it back, that kind if thing. The simulators (can) prevent you from needing to make system calls to "see" your results, likewise they can definitely help you work through hangs and crashes, which you will get and which IMO leads to giving up on the whole thing. Once you know more, you can switch to hardware or try another instruction set (each new one gets exponentially easier than the prior) leading to x86 if you by then still feel there is a need...With x86 I recommend going back to the early days, find an 8088/86 simulator, learn the original instruction set, then if you still feel the need, then skip to 80386 and newer. You will also need to be able to switch formats in your head, gnu using AT&T was a cardinal sin (gnu assembler folks commit these sins regularly BTW, it is almost expected), but unfortunately we now have these two competing formats. With practice you should easily be able to tell what format is being used on inspection of code, but mentally switching back and forth may still be a challenge.

OpenGL ES 2.0 debugging [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
So, I have an OpenGL ES 2.0 app. It compiles and runs in the iPhone/iPad simulators, on a real iPhone/iPad, and under Windows using Imgtec's emulator libraries (i.e. PVRVframe).
In said app, I have one particular draw call that results in no pixels written to the target, even though all the state I can query looks sensible (viewport, depth test/stencil test/cull/blend off, framebuffer complete etc), and AFAICT I am submitting sensible vertex data.
What I'm after at this point is a Pix / GPAD - like tool that will let me step through the scene and review state I cannot directly query from OpenGL at the point of the draw call in question (e.g. actual vertex/index buffer content).
Neither PVRTrace nor the OSX instruments appear to capture enough state for debugging this kind of problem. In particular, they do not capture vertex/index buffer or texture data (OSX instruments doesn't capture shader source either).
gDEBugger, previously the answer to this sort of question on Stack Overflow, is now at version 5.8 - it's gone free, which is nice, but no longer supports OpenGL ES 2 (under Windows, no ES2-renderable config is available through EGL; under OSX, there is no way to attach the debugger to an app running either in the simulator or on the real device) - which is not as nice.
Am I missing something obvious? What are my options? How do others debug their scenes?
There are several OpenGL ES 1.1/2.0 debugging tools from GPU vendors. Almost these tools require real device, but Imagination Technologies provides an emulation libraries and a tracing tool which you used. Did you use PVRTrace with PVRVFrame?
PowerVR (Imagination Technologies)
PVRVFrame is an emulation libraries for OpenGL ES 1.1/2.0 on OpenGL. And GL calls can be traced by PVRTrace with GUI.
PVRTrace can also connect with Linux ARMv7 devices.
Adreno (Qualcomm)
Adreno Profiler can trace GL calls with Adreno devices, such as Android with Snapdragon. Nexus One and many devices.
It can render GL calls that are executed on the target device.
WEBINAR: OPTIMIZE YOUR APP WITH ADRENO PROFILER
Tegra (NVIDIA)
PerfHUD ES has Frame Debugger as Adreno profiler. It require Tegra Development Kit.
Mali (ARM)
Mali GPU Performance Analysis Tool. It require Mali device. AFAIK, there are no Mali devices in the consumer market at the moment.
(I believe that gDEBugger 5.7 is the best tool for debugging OpenGL ES 1.1/2.0. But it is no longer available...)
It's possible in Xcode since version 4.2, c.f.
https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_2.html#//apple_ref/doc/uid/00200-SW5
I have found that gDebugger 5.7 for Windows IS still available here:
http://files.gremedy.com/downloads/gDEBugger-5_7.msi
I modified this URL from the one found at the top of this download page:
view-source:http://www.gremedy.com/downloading.php?platform=windows32
It may be possible to access the same version for other platforms via the same trick.
An old license file is available here:
http://www.geeks3d.com/20101207/3d-programming-gdebugger-advanced-opengl-debugger-now-free/
But it expired on Jan 31st, 2011.

What is the recommended way to hook Win32 APIs for a commmercial application? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
What is your recommendation for an API hooking library or code to be used in a commercial application?
I have looked at Microsoft Detours which seems to be very good, but definitely is out of budget for the profit I am expecting out of my application.
Is there any library that offers compatibility across WinXP and Vista (and Windows 7 if not too much to ask!)? Is there anyone with past experience in using such a library in a commercial product?
API hooking in Win32 isn't really possible in a system-wide sense. You can approximate it by injecting a DLL into each process and then patching each process from within. You can either use IAT patching (where you patch the calling binary) or a Detours-style patch (where you patch the callee).
Patching the caller (IAT patching) means that you need to enumerate every DLL that is loaded in the process and patch each one separately. You also would need to hook LoadLibrary in order to patch any new DLLs that are loaded on-the-fly.
Patching the callee (Detours) has the advantage that you only need to patch one location to have the hook apply to the entire process.
You have to do the per-process patching even if you're hooking APIs from shared system DLLs; the OS will invoke copy-on-write whereby when you patch the system DLL, the process is given a private copy to be patched.
DLL injecting gets to be a bit nasty, and again there are several techniques: AppInit_DLLs, which only works for processes that load USER32.DLL (and has several new restrictions in Vista and Windows 7), using SetWindowsHookEx, or by using CreateRemoteThread. Integrity levels in Vista and Windows 7 make it more difficult to inject into processes system-wide. Your app will need to run with administrator privileges and a high integrity level to be able to successfully pull it off.
Another technique is to hook the system services in kernel-mode. This requires writing a device driver, but it is basically the technique that Sysinternals Process Monitor uses (or at least did, once). This is a problem on 64-bit Vista and Win7 because of PatchGuard and the driver signing requirements. You can monitor some file system activity by using file system filter drivers.
You could also try NCodeHook lib (http://newgre.net/ncodehook), it is free and small.
I'd recommend MinHook. It's definitely the best free library you could find, and is not worse than Microsoft Detours.
What are you trying to do? is patching the import table sufficient? i've used a variation of http://jpassing.wordpress.com/2008/01/06/using-import-address-table-hooking-for-testing/ for some fun side projects at home.
You could try EasyHook, it looks to be useful. Can't patch "system wide" though, you would need something like a Proxy DLL for that.
http://www.codeplex.com/easyhook
Have you tried the Deviare API Hook ...
Deviare is licensed under a commercial and open source license (GNU General Public License version 3).

What is the opposite of Wine? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
What if I want to run native Unix-like applications on Windows? What's the best application out there?
Cygwin is closest to what you are looking for, though not exactly like Wine.
Cygwin is a Linux-like environment for Windows. It consists of two parts:
A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing substantial Linux API functionality.
A collection of tools which provide Linux look and feel.
It is not binary-compatible with Linux applications, you still need to rebuild them from source to run under Cygwin. Once rebuilt, however, they should work exactly like on Linux.
Not quite the same, but you could also run a full linux installation inside a VM such as Virtualbox: http://virtualbox.org/
Take a look at andLinux (based on coLinux).
From the site:
andLinux is a complete Ubuntu Linux
system running seamlessly in Windows
2000 based systems (2000, XP, 2003,
Vista; 32-bit versions only).
...
Although this technology is a bit like
running Linux in a virtual machine,
coLinux differs itself by being more
of a merger of Windows and the Linux
kernel and not an emulated PC, making
it more efficient. Xming is used as X
server and PulseAudio as sound server.
andLinux is not just for development
and runs almost all Linux applications
without modification.
Not Cygwin.
What Isn't Cygwin?
Cygwin is not a way to run native linux apps on Windows. You have to rebuild your application from source if you want it to run on Windows.
Cygwin is not a way to magically make native Windows apps aware of UNIX ® functionality, like signals, ptys, etc. Again, you need to build your apps from source if you want to take advantage of Cygwin functionality.
Cygwin will give a Linux-like shell but can not directly run linux applications in Windows. Cygwin "acts as a Linux API emulation layer providing substantial Linux API functionality."
At one point in the distant past, there was LINE Is Not an Emulator, which aimed to be exactly the inverse of Wine: provide binary compatibility for Linux executables running under Windows.
It kinda worked, at least as a proof of concept, but there isn't a big need for it.
If you're interested in porting those *nix applications to a Win32 environment, you might take a look at the MinGW project. I've mainly used it for GCC on windows, but they also provide an interesting environment called MSYS:
A Minimal SYStem providing a POSIX
compatible Bourne shell environment,
with a small collection of UNIX
command line tools. Primarily
developed as a means to execute the
configure scripts and Makefiles used
to build Open Source software, but
also useful as a general purpose
command line interface to replace
Windows cmd.exe.
Microsoft, for a while, offered SFU which sort of works for some things. Cygwin works much better.
If you're hoping for ABI Compatability, as wine offers unix systems for windows binaries, things are quite bleak. CoLinux also sort of works, but generally won't help you at all with any kind of graphical application, unless you configure a windows X11 server as well.
I've used andLinux which is built on coLinux. The organization has compiled an Ubuntu installation (Gutsy, I think, but I upgraded to Intrepid pretty easily).
One warning: development on andLinux is pretty slow -- the last beta has been out for almost a year.

Resources