We will show how to analyze your OpenResty or Nginx applications without debug symbols. Even in the absence of any debug information, it can analyze executables through machine learning, reconstruct debug symbols, and perform in-depth and comprehensive analysis through dynamic tracing. OpenResty XRay has the superpower of generating debug symbols from stripped executables, which makes it possible to get detailed information about C and Lua functions, source files, and source lines even without debug symbols.

Problem: Debug Symbols are missing

Run the ps command to see the full command line for an OpenResty or Nginx process.

Screenshot

We can see the path of the executable file for this process. This OpenResty is compiled from a source by the user herself.

Screenshot

Use the file command to inspect this executable. Copy the file path.

Screenshot

The file is stripped and lacks the any debug symbols or symbol table. We cannot find the corresponding debug symbol installation packages for this program either.

Screenshot

Then use the file command to check the LuaJIT Dynamic Linked Library.

Screenshot

Once again, the debug symbols for the LuaJIT file are also missing.

Screenshot

Automatically Analyze and Rebuild Debug Symbols

Fortunately, OpenResty XRay has the superpower to generate debug symbols from stripped executable files. It makes it possible to do in-depth and full analysis via dynamic tracing.

Open the OpenResty XRay Web console in the web browser.

Screenshot

Go to the “Guided Analysis” page.

Screenshot

Here, you can see different types of problems that you can diagnose.

Screenshot

Let’s select these four types of problems.

Screenshot

Click on “Next”.

Screenshot

Select the OpenResty application.

Screenshot

Select the worker process.

Screenshot

OpenResty XRay can analyze multiple language levels at the same time. We’ll keep both Lua and C/C++ selected.

Screenshot

Let’s start analyzing.

Screenshot

OpenResty XRay will check if any executable file is missing debug symbols and then try to rebuild them automatically. The symbol rebuild task is now running.

Screenshot

After the symbols have been successfully rebuilt, it starts executing all the relevant analyzers as usual.

Screenshot

Let’s stop analyzing.

Screenshot

We can see it automatically created an analysis report.

Screenshot

The first section of the report is for the CPU problem type.

Screenshot

First, check out Lua’s performance hotspots.

Screenshot

Click to see more details.

Screenshot

The hot code path was automatically inferred from this C-land CPU flame graph.

Screenshot

Click to enlarge the flame graph.

Screenshot

We can see all the C function names, including inlined functions.

Screenshot

It even shows the C source file name.

Screenshot

And the source code line number! It looks like magic, doesn’t it?

Screenshot

Click to see more.

Screenshot

This is the #1 hottest Lua code path using the most CPU time.

Screenshot

The close function is called by the generate function.

Screenshot

This is a Lua function called generate. It is defined in the Lua source file lua/report.lua.

Screenshot

The generate function was called by the generate_monthly_report defined in the lua/invoice.lua file.

Screenshot

Hover the mouse over the green box for the generate function. We can see the full path for the Lua source file in the tooltip.

Screenshot

The Lua source line number is 11.

Screenshot

Click the icon to copy the source file path.

Screenshot

Use the vim editor to open the source file. And look at the Lua code in this file. You can use any editors you like.

Screenshot

Go to line 11, as OpenResty XRay suggested. You can see the close function in the report. Even without the debug symbols, we can still get details about the hot Lua function and source line.

Screenshot

The generate function is used to query the database and generate reports.

Screenshot

Now, let’s check out the memory report.

Screenshot

On the Lua land, a good portion of the memory is taken up by dead Lua objects not yet released by the LuaJIT garbage collector.

Screenshot

Click to enlarge it.

Screenshot

Zoom in this data reference path.

Screenshot

In this path, the table is the data structure of all Lua modules loaded by the current Lua application. Apparently, these loaded Lua modules also take up a lot of memory.

Screenshot

Automatic analysis and reports

OpenResty XRay can also monitor online processes automatically and generate analysis reports.

Screenshot

Go to the “Insights” page.

Screenshot

You can find the automatic reports on the “Insights” page for daily and weekly periods. For this reason, you don’t have to use the “Guided Analysis” feature.

Screenshot

Though “Guided analysis” is useful for application development and demonstration purposes.

Screenshot

What is OpenResty XRay

OpenResty XRay is a dynamic-tracing product that automatically analyzes your running applications to troubleshoot performance problems, behavioral issues, and security vulnerabilities with actionable suggestions. Under the hood, OpenResty XRay is powered by our Y language targeting various runtimes like Stap+, eBPF+, GDB, and ODB, depending on the contexts.

If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.