# How to use Infiltrator?

**URL:** https://discourse.julialang.org/t/how-to-use-infiltrator/124305
**Category:** General Usage
**Created:** [December 31, 2024, 7:48am UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305 "2024-12-31T07:48:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![phma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phma/32/6576_2.png) [@phma](https://discourse.julialang.org/u/phma)
#### Post date: [December 31, 2024, 7:48am UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/1 "2024-12-31T07:48:05Z")

</div>

I have a `startup.jl` that looks like this:

```julia
try
  using Revise
catch e
  @warn "Error initializing Revise"
end
try
  using Infiltrator
catch e
  @warn "Error initializing Infiltrator"
end

```

I put `@infiltrate` in a function and got a compiler error. I then exited and restarted Julia and tried `using Infiltrator,<my package>`, with the same error. Searching the Web for the right way to do it, I found mention of `LOAD_PATH` and `@v#.#` (which is the second element of `Base.LOAD_PATH`) but no explanation I could understand of how to add `Infiltrator` to either of them. So how do I do it?

---

<div class="post-metadata">

### Author: ![RGerzaguet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rgerzaguet/32/45492_2.png) [@RGerzaguet](https://discourse.julialang.org/u/RGerzaguet)
#### Post date: [December 31, 2024, 8:03am UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/2 "2024-12-31T08:03:24Z")

</div>

Hello,

If you want to use Infiltrator inside a module you are currently writing (or a module developed by a third party), use this syntax

```julia
Main.infiltrate(@ __MODULE__ , Base.@locals, @ __FILE__ , @ __LINE__ )

```

intead of `@infiltrate`

Otherwise, you need to include `using Infiltrator` within the module you want to infiltrate, which is not always convenient.

---

<div class="post-metadata">

### Author: ![phma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phma/32/6576_2.png) [@phma](https://discourse.julialang.org/u/phma)
#### Post date: [December 31, 2024, 8:07am UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/3 "2024-12-31T08:07:03Z")

</div>

What about saying `using Infiltrator` and commenting it out when I don’t need it?

---

<div class="post-metadata">

### Author: ![RGerzaguet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rgerzaguet/32/45492_2.png) [@RGerzaguet](https://discourse.julialang.org/u/RGerzaguet)
#### Post date: [December 31, 2024, 8:09am UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/4 "2024-12-31T08:09:48Z")

</div>

You can, but you would need to add Infiltrator in the project dependencies. Possible for your projects, less suitable I would say for third party projects. But you can 🙂

---

<div class="post-metadata">

### Author: ![Janis\_Erdmanis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/janis_erdmanis/32/10869_2.png) [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)
#### Post date: [December 31, 2024, 3:47pm UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/5 "2024-12-31T15:47:49Z")

</div>

It is also possible to import `Infiltrator` in the `Base` from `startup.jl` and then export it from it:

```julia
@eval Base begin
    import Infiltrator: @infiltrate
    export @infiltrate
end

```

The only issue I have found is that Julia does not pick this up when it compiles the project’s package images in its own process.

---

<div class="post-metadata">

### Author: ![phma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phma/32/6576_2.png) [@phma](https://discourse.julialang.org/u/phma)
#### Post date: [January 7, 2025, 8:57am UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/6 "2025-01-07T08:57:18Z")

</div>

That didn’t work. Here’s my `startup.jl`:

```julia
try
  using Revise
catch e
  @warn "Error initializing Revise"
end
try
  using Infiltrator
  @eval Base begin
  import Infiltrator: @infiltrate
  export @infiltrate
end
catch e
  @warn "Error initializing Infiltrator"
end
try
  using Debugger
catch e
  @warn "Error initializing Debugger"
end

```

I put `@infiltrate` in my code, loaded it with `using`, and got an error “`@infiltrate` not defined”. I typed `@infiltrate` in the REPL and got an `infil>` prompt.

---

<div class="post-metadata">

### Author: ![Janis\_Erdmanis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/janis_erdmanis/32/10869_2.png) [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)
#### Post date: [January 7, 2025, 1:46pm UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/7 "2025-01-07T13:46:51Z")

</div>

I think you have stumbled on the case where you try to precompile code with the `@infiltrate` statements which does not work as `startup.jl` is not loaded by precompilation pipeline. The workflow that I use is:

1. Let the code to precompile without any `@infiltrate` statement in the code
2. Then add `@infiltrate` statements in the code and let `Revise` to recompile the necessary methods.

The first step could be resolved if we had ability to set a custom `startup.jl` file that is passed to precompilation, which could be ignored when running tests.

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [January 7, 2025, 2:02pm UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/8 "2025-01-07T14:02:48Z")

</div>

The documentation for usage is [here](https://juliadebug.github.io/Infiltrator.jl/dev/#Scripts-and-package-development).

1. Activate default global environment: `]activate @1.11`
2. Load development packages: `using Revise, Infiltrator`
3. Activate package environment: `]activate PackageName`
4. Load the unmodified package code: `using PackageName`
5. Add `Main.@infiltrate` lines inside package function code as breakpoints.
6. Call the package function from the REPL: `f(x)`

---

<div class="post-metadata">

### Author: ![Janis\_Erdmanis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/janis_erdmanis/32/10869_2.png) [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)
#### Post date: [January 7, 2025, 2:11pm UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/9 "2025-01-07T14:11:20Z")

</div>

With loading the `Infiltrator` in the `Base` and exporting `@infiltrate` from there one has the same workflow regarding steps 4. - 6. The small advantage is that it is possible to use `@infiltrate` over `Main.@infiltrate`.

---

<div class="post-metadata">

### Author: ![phma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phma/32/6576_2.png) [@phma](https://discourse.julialang.org/u/phma)
#### Post date: [January 8, 2025, 6:16am UTC](https://discourse.julialang.org/t/how-to-use-infiltrator/124305/10 "2025-01-08T06:16:09Z")

</div>

That worked. Though I already found the bug with Debugger (the code doesn’t take long to run).
