<div dir="ltr">Sounds good to me. You can also see llvm.codeview.annotation which does a similar thing, but it is modeled as having internal, invisible side effects. These should stay separate, but it may provide a guide for implementation.</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Mar 27, 2018 at 7:41 PM Hsiangkai Wang via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all,<br>
<br>
I would like to enhance LLVM debug info that supports setting<br>
breakpoint on labels in function.<br>
<br>
Generally, if users use GDB as their debugger, they could set<br>
breakpoints on labels in function. Following is an example.<br>
<br>
// C program<br>
static int<br>
myfunction (int arg)<br>
{<br>
  int i, j, r;<br>
<br>
  j = 0; /* myfunction location */<br>
  r = arg;<br>
<br>
 top:<br>
  ++j;  /* top location */<br>
<br>
  if (j == 10)<br>
    goto done;<br>
<br>
  for (i = 0; i < 10; ++i)<br>
    {<br>
      r += i;<br>
      if (j % 2)<br>
        goto top;<br>
    }<br>
<br>
 done:<br>
  return r;<br>
}<br>
<br>
int<br>
main (void)<br>
{<br>
  int i, j;<br>
<br>
  for (i = 0, j = 0; i < 1000; ++i)<br>
    j += myfunction (0);<br>
<br>
  return 0;<br>
}<br>
<br>
Following is the GDB commands to illustrate how to set breakpoints on labels.<br>
<br>
(gdb) b main<br>
Breakpoint 1 at 0x10298: file explicit.c, line 50.<br>
(gdb) r<br>
Starting program: /home/users/kai/sandbox/gdbtest/explicit-gcc<br>
<br>
Breakpoint 1, main () at explicit.c:50<br>
50  for (i = 0, j = 0; i < 1000; ++i)<br>
(gdb) b myfunction:top<br>
Breakpoint 2 at 0x10214: file explicit.c, line 26.<br>
(gdb) c<br>
Continuing.<br>
<br>
Breakpoint 2, myfunction (arg=0) at explicit.c:27<br>
27  ++j;  /\* top location */<br>
(gdb)<br>
<br>
However, LLVM does not generate debug information for labels. So, the<br>
feature could not work for binaries generated by clang. I also found<br>
that the problem is reported in PR35526 and PR36420. I propose an<br>
implementation plan to support debug information for labels.<br>
<br>
Following are the steps I propose to implement the feature.<br>
<br>
1. Define debug metadata and intrinsic functions for labels.<br>
<br>
First of all, we need to record debug information in LLVM IR. In LLVM<br>
IR, LLVM uses metadata and intrinsic function to keep debug<br>
information. So, I need to define new kind of metadata, DILabel, and<br>
new intrinsic function, llvm.dbg.label, to associate DILabel with<br>
label statement.<br>
<br>
DILabel will contain name of the label, file metadata, line number,<br>
and scope metadata.<br>
<br>
Intrinsic function llvm.dbg.label uses DILabel metadata as its parameter.<br>
<br>
2. Create MI instruction DBG_LABEL.<br>
<br>
I create new MI instruction DBG_LABEL to keep debug information after<br>
LLVM IR converted to MI.<br>
<br>
DBG_LABEL uses DILabel metadata as its parameter.<br>
<br>
3. Create data structure, SDDbgLabel, to store debug information of<br>
labels in SelectionDAG.<br>
<br>
In SelectionDAG, we need a data structure to keep debug information of<br>
label. It will keep DILabel metadata.<br>
<br>
4. Convert SDDbgLabel to DBG_LABEL in SelectionDAG.<br>
<br>
After EmitSchedule(), SelectionDAG will be converted to a list of MI<br>
instructions. In the function, we will generate DBG_LABEL MachineInstr<br>
from SDDbgLabel.<br>
<br>
For FastISel and GlobalISel, we could convert llvm.dbg.label to<br>
DBG_LABEL directly.<br>
<br>
5. Collect debug information of labels from MI listing to DebugHandlerBase.<br>
<br>
Before generating actual debug information in assembly format or<br>
object format, we need to keep debug format-independent data in<br>
DebugHandlerBase. Afterwards, we could convert these data to CodeView<br>
format or DWARF format.<br>
<br>
6. Create DWARF DIE specific data structure in DwarfDebug.<br>
<br>
In class DwarfDebug, we keep DWARF specific data structure for DILabel.<br>
<br>
7. Generate DW_TAG_label and fill details of DW_TAG_label.<br>
<br>
Finally, generating DW_TAG_label DIE and its attributes into DIE structure.<br>
<br>
I am looking forward to any thoughts & feedback!<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>