# How to programatically set a breakpoint to pseudo code view?

**URL:** <https://community.hex-rays.com/t/how-to-programatically-set-a-breakpoint-to-pseudo-code-view/365>\
**Category:** IDA General\
**Created:** [June 20, 2025, 6:16pm UTC](https://community.hex-rays.com/t/how-to-programatically-set-a-breakpoint-to-pseudo-code-view/365 "2025-06-20T18:16:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Linck](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@Linck](https://community.hex-rays.com/u/Linck)\
**Post date:** [June 20, 2025, 6:16pm UTC](https://community.hex-rays.com/t/how-to-programatically-set-a-breakpoint-to-pseudo-code-view/365/1 "2025-06-20T18:16:10Z")

</div>

Im using ida pro 9.1, python 3.13, how to make the breakpoints be also set in the pseudo code view?  
For **example** :

```auto
idaapi.add_bpt(0x7ff7fa2f4205, 0, idc.BPT_SOFT)
idaapi.enable_bpt(0x7ff7fa2f4205, True)

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/rays_hex/original/1X/256ed19a7db87699b1b88a81a26a7ba5a5f73e17.png)  
The api sets the red background only in the asm view, how i could also make it be visible in the pseudo code view? As seen in the picture line 267 isn’t getting colored.

---

<div class="post-metadata">

**Author:** ![ilfak](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/ilfak/32/49_2.png) [@ilfak](https://community.hex-rays.com/u/ilfak)\
**Post date:** [June 20, 2025, 8:10pm UTC](https://community.hex-rays.com/t/how-to-programatically-set-a-breakpoint-to-pseudo-code-view/365/2 "2025-06-20T20:10:53Z")

</div>

Try this:

```auto
ea = func_entry_address
lnnum = 267
b=bpt_t()
b.set_src_bpt("$%x" % ea, lnnum)
add_bpt(b)

```

---

<div class="post-metadata">

**Author:** ![Linck](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@Linck](https://community.hex-rays.com/u/Linck)\
**Post date:** [June 20, 2025, 10:25pm UTC](https://community.hex-rays.com/t/how-to-programatically-set-a-breakpoint-to-pseudo-code-view/365/3 "2025-06-20T22:25:14Z")

</div>

I tried this way but it throw an unhandled c++ exception

```auto
                try:
                    bpt.set_src_bpt("$%x" % 0x7ff7fa2f4205, 267)
                    ida_dbg.add_bpt(bpt)
                except Exception as e:
                    print(f"Error setting breakpoint: {e}")
                    return

```

What apis should i use for bpt\_t and add\_bpt? idaapi or ida\_dbg

---

<div class="post-metadata">

**Author:** ![Milanek](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@Milanek](https://community.hex-rays.com/u/Milanek)\
**Post date:** [June 21, 2025, 9:53am UTC](https://community.hex-rays.com/t/how-to-programatically-set-a-breakpoint-to-pseudo-code-view/365/4 "2025-06-21T09:53:08Z")

</div>

I experimented a bit and it turned out that the format string must be `$%X` (uppercase).

```auto
import idaapi

def add_breakpoint(ea, lnnum):
    """
    Adds a breakpoint at the specified address and line number.

    :param ea: The address where the breakpoint should be set.
    :param lnnum: The line number in the source code where the breakpoint should be set.
    """

    fnc: idaapi.func_t = idaapi.get_func(ea)
    if not fnc:
        print("Function not found at address 0x%X" % ea)
        return

    b = idaapi.bpt_t()
    # the line breakpoint is set at the start of the function
    b.set_src_bpt("$%X" % fnc.start_ea, lnnum)
    idaapi.add_bpt(b)

ea = idaapi.get_screen_ea()
lnnum = 8
add_breakpoint(ea, lnnum)

```

---

<div class="post-metadata">

**Author:** ![ilfak](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/ilfak/32/49_2.png) [@ilfak](https://community.hex-rays.com/u/ilfak)\
**Post date:** [June 21, 2025, 10:43am UTC](https://community.hex-rays.com/t/how-to-programatically-set-a-breakpoint-to-pseudo-code-view/365/5 "2025-06-21T10:43:07Z")

</div>

Thank you, very much Milan!
