~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to vm_dump.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
  vm_dump.c -
4
4
 
5
 
  $Author: nobu $
6
 
  $Date: 2007-06-05 13:49:54 +0900 (火, 05  6月 2007) $
 
5
  $Author: ko1 $
 
6
  $Date: 2007-08-13 04:09:15 +0900 (月, 13  8月 2007) $
7
7
 
8
8
  Copyright (C) 2004-2006 Koichi Sasada
9
9
 
10
10
**********************************************************************/
11
11
 
12
12
 
13
 
#include <ruby.h>
14
 
#include <node.h>
 
13
#include "ruby/ruby.h"
 
14
#include "ruby/node.h"
15
15
 
16
 
#include "yarvcore.h"
 
16
#include "vm_core.h"
17
17
#include "vm.h"
18
18
 
19
19
#define MAX_POSBUF 128
46
46
        bp = cfp->bp - th->stack;
47
47
    }
48
48
 
49
 
    switch (cfp->magic) {
 
49
    switch (VM_FRAME_TYPE(cfp)) {
50
50
      case FRAME_MAGIC_TOP:
51
51
        magic = "TOP";
52
52
        break;
100
100
        else {
101
101
            pc = cfp->pc - cfp->iseq->iseq_encoded;
102
102
            iseq_name = RSTRING_PTR(cfp->iseq->name);
103
 
            line = th_get_sourceline(cfp);
 
103
            line = vm_get_sourceline(cfp);
104
104
            if (line) {
105
105
                char fn[MAX_POSBUF+1];
106
106
                snprintf(fn, MAX_POSBUF, "%s", RSTRING_PTR(cfp->iseq->filename));
114
114
        line = -1;
115
115
    }
116
116
 
117
 
    fprintf(stderr, "c:%04ld ",
 
117
    fprintf(stderr, "c:%04d ",
118
118
            (rb_control_frame_t *)(th->stack + th->stack_size) - cfp);
119
119
    if (pc == -1) {
120
120
        fprintf(stderr, "p:---- ");
123
123
        fprintf(stderr, "p:%04d ", pc);
124
124
    }
125
125
    fprintf(stderr, "s:%04d b:%04d ", cfp->sp - th->stack, bp);
126
 
    fprintf(stderr, lfp_in_heap == ' ' ? "l:%06d " : "l:%06p ", lfp % 10000);
127
 
    fprintf(stderr, dfp_in_heap == ' ' ? "d:%06d " : "d:%06p ", dfp % 10000);
 
126
    fprintf(stderr, lfp_in_heap == ' ' ? "l:%06d " : "l:%06x ", lfp % 10000);
 
127
    fprintf(stderr, dfp_in_heap == ' ' ? "d:%06d " : "d:%06x ", dfp % 10000);
128
128
    fprintf(stderr, "%-6s ", magic);
129
129
    if (line) {
130
130
        fprintf(stderr, "%s", posbuf);
141
141
void
142
142
vm_stack_dump_raw(rb_thread_t *th, rb_control_frame_t *cfp)
143
143
{
 
144
#if 0
144
145
    VALUE *sp = cfp->sp, *bp = cfp->bp;
145
146
    VALUE *lfp = cfp->lfp;
146
147
    VALUE *dfp = cfp->dfp;
164
165
 
165
166
        fprintf(stderr, "\n");
166
167
    }
 
168
#endif
 
169
 
167
170
    fprintf(stderr, "-- control frame ----------\n");
168
171
    while ((void *)cfp < (void *)(th->stack + th->stack_size)) {
169
172
        control_frame_dump(th, cfp);
232
235
    VALUE *lfp = cfp->lfp;
233
236
    VALUE *dfp = cfp->dfp;
234
237
 
235
 
    int argc, local_size;
 
238
    int argc = 0, local_size;
236
239
    const char *name;
237
240
    rb_iseq_t *iseq = cfp->iseq;
238
241
 
260
263
 
261
264
    /* stack trace header */
262
265
 
263
 
    if (cfp->magic == FRAME_MAGIC_METHOD ||
264
 
        cfp->magic == FRAME_MAGIC_TOP ||
265
 
        cfp->magic == FRAME_MAGIC_BLOCK ||
266
 
        cfp->magic == FRAME_MAGIC_CLASS ||
267
 
        cfp->magic == FRAME_MAGIC_PROC ||
268
 
        cfp->magic == FRAME_MAGIC_LAMBDA ||
269
 
        cfp->magic == FRAME_MAGIC_CFUNC ||
270
 
        cfp->magic == FRAME_MAGIC_IFUNC ||
271
 
        cfp->magic == FRAME_MAGIC_EVAL) {
 
266
    if (VM_FRAME_TYPE(cfp) == FRAME_MAGIC_METHOD ||
 
267
        VM_FRAME_TYPE(cfp) == FRAME_MAGIC_TOP ||
 
268
        VM_FRAME_TYPE(cfp) == FRAME_MAGIC_BLOCK ||
 
269
        VM_FRAME_TYPE(cfp) == FRAME_MAGIC_CLASS ||
 
270
        VM_FRAME_TYPE(cfp) == FRAME_MAGIC_PROC ||
 
271
        VM_FRAME_TYPE(cfp) == FRAME_MAGIC_LAMBDA ||
 
272
        VM_FRAME_TYPE(cfp) == FRAME_MAGIC_CFUNC ||
 
273
        VM_FRAME_TYPE(cfp) == FRAME_MAGIC_IFUNC ||
 
274
        VM_FRAME_TYPE(cfp) == FRAME_MAGIC_EVAL) {
272
275
 
273
276
        VALUE *ptr = dfp - local_size;
274
277
 
297
300
            else {
298
301
                rstr = rb_inspect(*ptr);
299
302
            }
300
 
            fprintf(stderr, "  stack %2d: %8s (%ld)\n", i, StringValueCStr(rstr),
 
303
            fprintf(stderr, "  stack %2d: %8s (%d)\n", i, StringValueCStr(rstr),
301
304
                   ptr - th->stack);
302
305
        }
303
306
    }
304
 
    else if (cfp->magic == FRAME_MAGIC_FINISH) {
 
307
    else if (VM_FRAME_TYPE(cfp) == FRAME_MAGIC_FINISH) {
305
308
        if ((th)->stack + (th)->stack_size > (VALUE *)(cfp + 2)) {
306
309
            stack_dump_each(th, cfp + 1);
307
310
        }
310
313
        }
311
314
    }
312
315
    else {
313
 
        rb_bug("unsupport frame type: %08lx", cfp->magic);
 
316
        rb_bug("unsupport frame type: %08lx", VM_FRAME_TYPE(cfp));
314
317
    }
315
318
}
316
319
 
334
337
        dfp = -1;
335
338
 
336
339
    cfpi = ((rb_control_frame_t *)(th->stack + th->stack_size)) - cfp;
337
 
    fprintf(stderr, "  [PC] %04d, [SP] %04ld, [LFP] %04d, [DFP] %04d, [CFP] %04d\n",
 
340
    fprintf(stderr, "  [PC] %04d, [SP] %04d, [LFP] %04d, [DFP] %04d, [CFP] %04d\n",
338
341
           pc, cfp->sp - th->stack, lfp, dfp, cfpi);
339
342
}
340
343
 
351
354
{
352
355
    rb_iseq_t *iseq = cfp->iseq;
353
356
 
354
 
    if (iseq != 0 && cfp->magic != FRAME_MAGIC_FINISH) {
 
357
    if (iseq != 0 && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
355
358
        VALUE *seq = iseq->iseq;
356
359
        int pc = cfp->pc - iseq->iseq_encoded;
357
360
 
 
361
        printf("%3d ", VM_CFP_CNT(th, cfp));
358
362
        ruby_iseq_disasm_insn(0, seq, pc, iseq, 0);
359
363
    }
360
364
 
396
400
    printf
397
401
        ("--------------------------------------------------------------\n");
398
402
#endif
399
 
 
400
 
#if VMDEBUG > 9
401
 
    GC_CHECK();
402
 
#endif
403
403
}
404
404
 
405
405
#ifdef COLLECT_USAGE_ANALYSIS
425
425
    VALUE ihash;
426
426
    VALUE cv;
427
427
 
428
 
    SET_YARV_STOP();
429
 
 
430
428
    if (usage_hash == 0) {
431
429
        usage_hash = rb_intern("USAGE_ANALISYS_INSN");
432
430
        bigram_hash = rb_intern("USAGE_ANALISYS_INSN_BIGRAM");
433
431
    }
434
 
    uh = rb_const_get(mYarvCore, usage_hash);
 
432
    uh = rb_const_get(rb_cVM, usage_hash);
435
433
    if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) {
436
434
        ihash = rb_hash_new();
437
435
        rb_hash_aset(uh, INT2FIX(insn), ihash);
451
449
        ary[1] = INT2FIX(insn);
452
450
        bi = rb_ary_new4(2, &ary[0]);
453
451
 
454
 
        uh = rb_const_get(mYarvCore, bigram_hash);
 
452
        uh = rb_const_get(rb_cVM, bigram_hash);
455
453
        if ((cv = rb_hash_aref(uh, bi)) == Qnil) {
456
454
            cv = INT2FIX(0);
457
455
        }
458
456
        rb_hash_aset(uh, bi, INT2FIX(FIX2INT(cv) + 1));
459
457
    }
460
458
    prev_insn = insn;
461
 
 
462
 
    SET_YARV_START();
463
459
}
464
460
 
465
461
/* from disasm.c */
477
473
    VALUE valstr;
478
474
    VALUE cv;
479
475
 
480
 
    SET_YARV_STOP();
481
 
 
482
476
    if (usage_hash == 0) {
483
477
        usage_hash = rb_intern("USAGE_ANALISYS_INSN");
484
478
    }
485
479
 
486
 
    uh = rb_const_get(mYarvCore, usage_hash);
 
480
    uh = rb_const_get(rb_cVM, usage_hash);
487
481
    if ((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil) {
488
482
        ihash = rb_hash_new();
489
483
        rb_hash_aset(uh, INT2FIX(insn), ihash);
500
494
        cv = INT2FIX(0);
501
495
    }
502
496
    rb_hash_aset(ophash, valstr, INT2FIX(FIX2INT(cv) + 1));
503
 
 
504
 
    SET_YARV_START();
505
497
}
506
498
 
507
499
void
528
520
 
529
521
    VALUE cv;
530
522
 
531
 
    SET_YARV_STOP();
532
 
 
533
523
    if (usage_hash == 0) {
534
524
        char buff[0x10];
535
525
        int i;
547
537
    }
548
538
    valstr = syms[reg][isset];
549
539
 
550
 
    uh = rb_const_get(mYarvCore, usage_hash);
 
540
    uh = rb_const_get(rb_cVM, usage_hash);
551
541
    if ((cv = rb_hash_aref(uh, valstr)) == Qnil) {
552
542
        cv = INT2FIX(0);
553
543
    }
554
544
    rb_hash_aset(uh, valstr, INT2FIX(FIX2INT(cv) + 1));
555
 
 
556
 
    SET_YARV_START();
557
545
}
558
546
 
559
547
 
576
564
}
577
565
 
578
566
void
579
 
yarv_bug(void)
 
567
rb_vm_bugreport(void)
580
568
{
581
569
    rb_thread_t *th = GET_THREAD();
582
570
    VALUE bt;
585
573
        int i;
586
574
        SDR();
587
575
 
588
 
        bt = th_backtrace(th, 0);
 
576
        bt = vm_backtrace(th, 0);
589
577
        if (TYPE(bt) == T_ARRAY)
590
578
        for (i = 0; i < RARRAY_LEN(bt); i++) {
591
579
            dp(RARRAY_PTR(bt)[i]);