Debugging templated functions

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Debugging templated functions

444 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Wed May 25 04:21:24 MST 2016
Hello dear LPC users,

I would like to put breakpoints inside some templated C++ functions.
However, when I attempt to do so, I get the following error:

Quote:

15: Target error from Set break/watch
  15: Target error from Set break/watch
  Unable to set an execution break - no resource available.




Quote:

Error in final launch sequence
Failed to execute MI command:
-exec-continue
Error message from debugger back end:
Warning:\nCannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 1.\n
Cannot insert hardware breakpoint 3.\n
Could not insert hardware breakpoints:\nYou may have requested too many hardware breakpoints/watchpoints.\n
Warning:\nCannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 2.\n
Cannot insert hardware breakpoint 1.\n
Cannot insert hardware breakpoint 3.\n
Could not insert hardware breakpoints:\nYou may have requested too many hardware breakpoints/watchpoints.\n



I suspect that this is either because the incriminating function is defined in a header file or because dbg is forced to put a breakpoint in each specialisation of the templated function (I indeed declare several instances with different typenames).
Is there a way to limit the breakpoint insertion to a specific instance of the templated function, perhaps using the mangled names?


Thanks in advance!
0 Kudos
5 Replies

341 Views
lpcware
NXP Employee
NXP Employee
bump
0 Kudos

341 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Tue Jun 07 07:32:16 MST 2016
Unfortunately even the forum makes it hard to do metaprogramming so you couldn't see the angular brackets i've actually used.
To make it clear, here's the ways i tried (spaces only here, not in gdb):

object_name.function_name < param > ()
class_name::function_name < param > ()
&class_name::function_name < param > ()
0 Kudos

341 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LessThanZero on Fri Jun 03 08:17:02 MST 2016


As a function breakpoint, did you try using the template name including the angle brackets? That's supposed to work. Alternatively, you might try the template breakpoint name directly into the LPCXpresso GDB console.This would bypass the IDE in case there's an Eclipse issue of some sort.

Regards,
LessThanZero
0 Kudos

341 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Fri Jun 03 07:20:35 MST 2016

Quote: LessThanZero
It sounds like a line breakpoint ieaves GDB with no option other than set a break in every template instance. If you navigate to the IDE Breakpoint window, you'll find a pulldown menu. Try setting your template name as a "Function Breakpoint (C/C++)..." using the particular instance name.To use a well worn example, if you have a template function foo with a
<?php

    foo<int>
    foo<char>

    *Not PHP, but the <code> tags don't seem to work for me.
?>

instance, specify the instance name you want to break on. It's understood this isn't particularly convenient compared with using a line breakpoint.

One other alternative is more of a work around to place the expanded template code in RAM. The downside is GDB still sets breaks in each template instance which may not be what you want. The good news is, the debugger is not likely to run out of software breaks. Review this link for more information on how to place your code in RAM.

Placing specific functions into RAM blocks

Regards,
LessThanZero




Hi LessThanZero,

thanks for the useful response!
I tried to follow your advice on setting a function breakpoint but unfortunately it didn't stop the execution. Since it was a member (templated) function and since I had never used a function breakpoint before, I tried setting it up in different ways (object_name.function_name<blah>() or class_name::function_name<blah>() or &class_name::function_name<blah>()) but none of them worked.

I will try by uploading the function in RAM as soon as I will put my hands on that project again.

PS: you're right, the code tag messes up the angular brakets :s


0 Kudos

341 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LessThanZero on Fri May 27 07:44:00 MST 2016
It sounds like a line breakpoint ieaves GDB with no option other than set a break in every template instance. If you navigate to the IDE Breakpoint window, you'll find a pulldown menu. Try setting your template name as a "Function Breakpoint (C/C++)..." using the particular instance name.To use a well worn example, if you have a template function foo with a
<?php

    foo<int>
    foo<char>

    *Not PHP, but the <code> tags don't seem to work for me.
?>

instance, specify the instance name you want to break on. It's understood this isn't particularly convenient compared with using a line breakpoint.

One other alternative is more of a work around to place the expanded template code in RAM. The downside is GDB still sets breaks in each template instance which may not be what you want. The good news is, the debugger is not likely to run out of software breaks. Review this link for more information on how to place your code in RAM.

Placing specific functions into RAM blocks

Regards,
LessThanZero
0 Kudos