[R] Debugging dynloaded C-code with gdb

Peter Holzer holzer at stat.math.ethz.ch
Mon Oct 2 19:55:42 CEST 2000


Dear R users

I have started to use gdb for debugging dynloaded C code as described in
`Writing R Extensions'. Unfortunately I have run into several problems that
I haven't been able to solve:

- using `n': how comes that the same line of code appears up to three times
  (and inbetween the next line and maybe even the second next one?)

- using `print' resp. `display': How comes the variable values are
  different from those shown by fprintf? How comes the variable values
  change when actually no value is assigned to them (and I use `n', not
  `s')?

Let me give you a short piece of my code (the line number in brackets)

(216)  dyPixel = loc_mat[k][l] / 16;
(217)  dxPixel = loc_mat[k][l] - 16 * dyPixel;
(218)  ynb = k + (dyPixel - 8) / 8.;
(219)  xnb = l + (dxPixel - 8) / 8.;
(220)  fprintf(stderr, "%i %i %f %f\n", dyPixel, dxPixel, ynb, xnb);
(221)  linkLength = hypot(xnb-x, ynb-x);

and the corresponding output of gdb, using `n' - note that a) the
linenumbers show up in the sequence 216, 217, 218, 216, 217, 218, 219, 218,
219, 220, 221 and b) that the values of `xnb' and `ynb' in the end do not
correspond with those shown by fprintf in the second last statement:

Breakpoint 7, edgelGrouping (
    curv_vec=0x44262987 "D", 'ÿ' <repeats 199 times>..., curv_mat=0x442620cc, 
    or_mat=0x442c90a4, loc_mat=0x4433007c, xdim=752, ydim=558, 
    hashTable=0xbff7f044, hashInd=0xbfffdf84) at glazer.c:216
216		      dyPixel = loc_mat[k][l] / 16;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 1143349452
3: dyPixel = 478
(gdb) n
217		      dxPixel = loc_mat[k][l] - 16 * dyPixel;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 1144553335
3: dyPixel = 1144193148
(gdb) n
218		      ynb = k + (dyPixel - 8) / 8.;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 136
3: dyPixel = 1144193148
(gdb) n
216		      dyPixel = loc_mat[k][l] / 16;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 136
3: dyPixel = 1144193148
(gdb) n
217		      dxPixel = loc_mat[k][l] - 16 * dyPixel;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 136
3: dyPixel = 8
(gdb) n
218		      ynb = k + (dyPixel - 8) / 8.;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 8
3: dyPixel = 8
(gdb) n
219		      xnb = l + (dxPixel - 8) / 8.;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 8
3: dyPixel = 8
(gdb) n
218		      ynb = k + (dyPixel - 8) / 8.;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 8
3: dyPixel = 8
(gdb) n
219		      xnb = l + (dxPixel - 8) / 8.;
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 8
3: dyPixel = 8
(gdb) n
220		      fprintf(stderr, "%i %i %f %f\n", dyPixel, dxPixel, ynb, xnb);
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 8
3: dyPixel = 8
(gdb) n
8 8 477.000000 583.000000
221		      linkLength = hypot(xnb-x, ynb-x);
6: xnb = 9.1245819032751532e-313
5: ynb = 0
4: dxPixel = 0
3: dyPixel = 1075452551
(gdb) 


I would be grateful for any hints.

Peter
____________________________________________________________

Peter Holzer                      phone: + 41 1 632 46 34
Seminar fuer Statistik, LEO C14   fax:   + 41 1 632 12 28
(Leonhardstr. 27)                  <holzer at stat.math.ethz.ch>
ETH (Federal Inst. Technology)
8092 Zurich                       http://www.stat.math.ethz.ch/~holzer/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list