# Attaching a debugger to a running Julia program and printing local variables

**URL:** <https://discourse.julialang.org/t/attaching-a-debugger-to-a-running-julia-program-and-printing-local-variables/99961>\
**Category:** General Usage\
**Tags:** debug\
**Created:** [June 6, 2023, 7:44pm UTC](https://discourse.julialang.org/t/attaching-a-debugger-to-a-running-julia-program-and-printing-local-variables/99961 "2023-06-06T19:44:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [June 6, 2023, 7:44pm UTC](https://discourse.julialang.org/t/attaching-a-debugger-to-a-running-julia-program-and-printing-local-variables/99961/1 "2023-06-06T19:44:09Z")

</div>

I have a long-running Julia (nightly) script that seems to enter an infinite loop sometimes after running for several hours. Julia is started with `ENABLE_GDBLISTENER=1` and with `-g2`.

Attaching with GDB (`gdb -p PID`) works fine, backtraces and breakpoints work fine. Even the GDB TUI mode (interactive source view) works!

However, I’m not sure how to print local Julia variables. For example, I’m currently in a large Julia function that has the local variable `step::Int`. How do I print the value of `step`? Doing `p step` in GDB works, but seems to refer to some C function named `step`, instead of to my local variable.

Any ideas?

BTW, if I’m on Linux, is it better to use GDB or LLDB? Any other debuggers that allow attaching to a running Julia program?

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [June 6, 2023, 7:57pm UTC](https://discourse.julialang.org/t/attaching-a-debugger-to-a-running-julia-program-and-printing-local-variables/99961/2 "2023-06-06T19:57:27Z")

</div>

Perhaps you might use instructions for [logging](https://docs.julialang.org/en/v1/stdlib/Logging/) events.
