-
Notifications
You must be signed in to change notification settings - Fork 17
Docs : documentation for LLDB debugging #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,116 @@ | ||||||||||
| #### 1. Go to the Source Directory | ||||||||||
|
|
||||||||||
| Rebuild R with debugging symbols so LLDB can access C source lines and | ||||||||||
| variables. Make sure your build uses the `-g` flag. Open a bash terminal | ||||||||||
| and navigate to the root of your project’s source directory. | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| cd $TOP_SRCDIR | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| #### 2. Run R Using the Debug Wrapper Script | ||||||||||
|
|
||||||||||
| Run R through the wrapper script (`launch_r.sh`) that | ||||||||||
| sets up `LD_PRELOAD` and debugging environment: | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| ./scripts/launch_r.sh | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| This ensures the ptrace helper library is loaded | ||||||||||
| for debugging support. | ||||||||||
|
Comment on lines
+5
to
+21
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user does not have to do this, the way |
||||||||||
|
|
||||||||||
| #### 3. Attach LLDB to the Running R Process | ||||||||||
|
|
||||||||||
| Find the process ID (PID) of your R session. You | ||||||||||
| can do this within R, Start an R terminal by using | ||||||||||
| the command R in the terminal,then: | ||||||||||
|
Comment on lines
+25
to
+27
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. People should not run R in the bash terminal, they should start an R terminal, e.g. by clicking on R (not attached) or by using the Command Palette. We don't need to document how to start an R terminal as that is covered in an earlier tutorial.
Suggested change
|
||||||||||
|
|
||||||||||
| ```r | ||||||||||
| Sys.getpid() | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Attach LLDB to this PID, using the command palette type | ||||||||||
| `LLDB: Attach to Process` then select the PID you just | ||||||||||
| got or you can do this via the terminal: | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| lldb -p <PID> | ||||||||||
| ``` | ||||||||||
|
Comment on lines
+33
to
+39
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The aim is not to use lldb from the command line, but to use the LLDB extension as I demoed in our meeting the other week. So once you have the pid from R, go to the Run and Debug panel and click the green arrow (Start Debugging to launch the debugger (as defined in the launch.json file). This opens a dialog where you type in the pid to select the R process to attach to. |
||||||||||
|
|
||||||||||
| #### 4. Set a Breakpoint in Native C Code | ||||||||||
|
|
||||||||||
| For example, to debug `rlogis.c`, set a breakpoint at | ||||||||||
| the start of its function in `rlogis.c` (line 25): | ||||||||||
|
|
||||||||||
| ```lldb | ||||||||||
| breakpoint set --file rlogis.c --line 25 | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| You can do this by clicking the r | ||||||||||
| ed dot on the left side | ||||||||||
| of a line in a program as shown i | ||||||||||
| n the screenshot below: | ||||||||||
|
Comment on lines
+50
to
+53
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines should not be so narrow! it should be okay to have lines that are 80 characters width. |
||||||||||
|
|
||||||||||
|  | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Screenshots should not use dark mode - ideally they would be take from GitHub Codespaces as that is the default interface, but of course that requires #267 to be merged in first, so using light mode locally should be okay. |
||||||||||
|
|
||||||||||
| #### 5. Trigger the Function in R | ||||||||||
|
|
||||||||||
| Use this command directly in the LLDB debug | ||||||||||
| console to call the C function and see its | ||||||||||
| result: | ||||||||||
|
|
||||||||||
| ```lldb | ||||||||||
| expr (double)rlogis(1.0, 1.0) | ||||||||||
| ``` | ||||||||||
|
Comment on lines
+59
to
+65
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is that we trigger the breakpoint from R. So within the R terminal, we type the R command rlogis(1)This R wrapper will call the C function and stop at the breakpoint in the C code. |
||||||||||
|
|
||||||||||
| This will activate your breakpoint and pause | ||||||||||
| at the specified line for inspection as shown | ||||||||||
| below. | ||||||||||
|
|
||||||||||
|  | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
|
|
||||||||||
| #### 6. Debugging Actions in LLDB | ||||||||||
|
|
||||||||||
| After pausing at a breakpoint, use the LLDB | ||||||||||
| toolbar buttons and commands to control execution: | ||||||||||
|
|
||||||||||
| - **Continue Execution:** Resume running until | ||||||||||
| the next breakpoint (Run icon ▷ in blue). | ||||||||||
| - **Step Through the Code:** Move line-by-line, | ||||||||||
| stepping into functions (Step Into ↓ in blue) | ||||||||||
| or stepping out of the current function | ||||||||||
| (Step Out ↑ in blue). | ||||||||||
| - **Stop Execution:** Pause the running process | ||||||||||
| (interrupt command, icon may not always be shown). | ||||||||||
| - **Additional Controls:** | ||||||||||
| ack (↶ in blue) for reverse debugging | ||||||||||
| if available. | ||||||||||
| t (⟲ in green) to restart the session. | ||||||||||
| nect (🔗 in orange) to detach the debugger | ||||||||||
| while leaving the process running. | ||||||||||
|
Comment on lines
+84
to
+91
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would only document the buttons that are visible in the screenshot (so not Stop Execution or Back for reverse debugging). As we are attaching to a running process, restart and disconnect have the same behaviour: they stop the debugger and return to R. (Note you have some letters missing here). It would be nice to use actual pictures of the buttons here. According to ChatGPT you could do this in markdown Click the {: .icon } to open the menu.Then in docs/css/custom.css (which should be included via extra_css in mkdocs.yml): .icon {
height: 20px;
vertical-align: middle;
} |
||||||||||
|
|
||||||||||
| Use these controls to navigate and inspect your native | ||||||||||
| C code during debugging within R. | ||||||||||
|
|
||||||||||
| #### 7. Inspect Variables and Expressions | ||||||||||
|
|
||||||||||
| LLDB allows watching variables and | ||||||||||
| evaluating expressions. For example, | ||||||||||
| in the context of debugging `rlogis`, | ||||||||||
| you can inspect the variable `u` or | ||||||||||
| watch the result of an expression: | ||||||||||
|
|
||||||||||
| ```lldb | ||||||||||
| expr u | ||||||||||
| expr log(u / 1.0 - u) | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| The side panel or variable/watch | ||||||||||
| window updates as you step through | ||||||||||
| the code. Finally, when you exit | ||||||||||
| the debugger using the disconnect | ||||||||||
| button or te exit command, the | ||||||||||
| screen shown below is displayed: | ||||||||||
|
Comment on lines
+98
to
+114
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea here was to document the Watch panel in the Run and Debug panel on VS Code:
As you can see, you can watch simple expressions like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
|
|
||||||||||
|  | ||||||||||



There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They may have already built R with the correct CFLAGS. So here we can say something like:
You need to add the relevant links: "Step 5" should link to "5) Set CFLAGS (Optional—For Debugging C Code)" - you will need to add an anchor somehow, it may be easier to convert the item headers to proper HTML headings of the appropriate level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we will update the docs to always use
CFLAGS="-g -O0", we can delete this part. It is probably best to start with a step like:and then go on to launch an R terminal, etc.