@@ -364,6 +364,54 @@ Address parseAddress(String addr) {
364
364
return VM .getVM ().getDebugger ().parseAddress (addr );
365
365
}
366
366
367
+ String fillHexString (Address a , int width ) {
368
+ String s = "0x0" ;
369
+ if (a != null ) {
370
+ s = a .toString ();
371
+ }
372
+ if (s .length () != width ) {
373
+ return s .substring (0 , 2 ) + "000000000000000000000" .substring (0 , width - s .length ()) + s .substring (2 );
374
+ }
375
+ return s ;
376
+ }
377
+
378
+ class AddressRange {
379
+ private Address start ;
380
+ private Address end ;
381
+ AddressRange (Address start , Address end ) {
382
+ this .start = start ;
383
+ this .end = end ;
384
+ }
385
+ Address getStart () {return start ;}
386
+ Address getEnd () {return end ;}
387
+ }
388
+
389
+ // Parses either address[/count] or address,address into address start/end values
390
+ AddressRange parseAddressRange (String arg , int formatSize ) {
391
+ Pattern args1 = Pattern .compile ("^(0x[0-9a-f]+)(/([0-9]*))?$" );
392
+ Pattern args2 = Pattern .compile ("^(0x[0-9a-f]+),(0x[0-9a-f]+)$" );
393
+ Matcher m1 = args1 .matcher (arg );
394
+ Matcher m2 = args2 .matcher (arg );
395
+ Address start = null ;
396
+ Address end = null ;
397
+
398
+ if (m1 .matches ()) {
399
+ start = VM .getVM ().getDebugger ().parseAddress (m1 .group (1 ));
400
+ int count = 1 ;
401
+ if (m1 .group (2 ) != null ) {
402
+ count = Integer .parseInt (m1 .group (3 ));
403
+ }
404
+ end = start .addOffsetTo (count * formatSize );
405
+ return new AddressRange (start , end );
406
+ } else if (m2 .matches ()) {
407
+ start = VM .getVM ().getDebugger ().parseAddress (m2 .group (1 ));
408
+ end = VM .getVM ().getDebugger ().parseAddress (m2 .group (2 ));
409
+ return new AddressRange (start , end );
410
+ } else {
411
+ return null ;
412
+ }
413
+ }
414
+
367
415
private final Command [] commandList = {
368
416
new Command ("reattach" , true ) {
369
417
public void doit (Tokens t ) {
@@ -409,65 +457,40 @@ public void doit(Tokens t) {
409
457
}
410
458
}
411
459
},
412
- new Command ("examine" , "examine [ address/count ] | [ address,address]" , false ) {
413
- Pattern args1 = Pattern .compile ("^(0x[0-9a-f]+)(/([0-9]*)([a-z]*))?$" );
414
- Pattern args2 = Pattern .compile ("^(0x[0-9a-f]+),(0x[0-9a-f]+)(/[a-z]*)?$" );
415
-
416
- String fill (Address a , int width ) {
417
- String s = "0x0" ;
418
- if (a != null ) {
419
- s = a .toString ();
420
- }
421
- if (s .length () != width ) {
422
- return s .substring (0 , 2 ) + "000000000000000000000" .substring (0 , width - s .length ()) + s .substring (2 );
423
- }
424
- return s ;
425
- }
426
-
460
+ new Command ("examine" , "examine { address[/count] | address,address }" , false ) {
427
461
public void doit (Tokens t ) {
428
462
if (t .countTokens () != 1 ) {
429
463
usage ();
430
464
} else {
431
465
String arg = t .nextToken ();
432
- Matcher m1 = args1 .matcher (arg );
433
- Matcher m2 = args2 .matcher (arg );
434
- Address start = null ;
435
- Address end = null ;
436
466
int formatSize = (int )VM .getVM ().getAddressSize ();
437
-
438
- if (m1 .matches ()) {
439
- start = VM .getVM ().getDebugger ().parseAddress (m1 .group (1 ));
440
- int count = 1 ;
441
- if (m1 .group (2 ) != null ) {
442
- count = Integer .parseInt (m1 .group (3 ));
443
- }
444
- end = start .addOffsetTo (count * formatSize );
445
- } else if (m2 .matches ()) {
446
- start = VM .getVM ().getDebugger ().parseAddress (m2 .group (1 ));
447
- end = VM .getVM ().getDebugger ().parseAddress (m2 .group (2 ));
448
- } else {
467
+ AddressRange addressRange = parseAddressRange (arg , formatSize );
468
+ if (addressRange == null ) {
449
469
usage ();
450
470
return ;
451
471
}
472
+ Address start = addressRange .getStart ();
473
+ Address end = addressRange .getEnd ();
474
+
452
475
int line = 80 ;
453
476
int formatWidth = formatSize * 8 / 4 + 2 ;
454
477
455
- out .print (fill (start , formatWidth ));
478
+ out .print (fillHexString (start , formatWidth ));
456
479
out .print (": " );
457
480
int width = line - formatWidth - 2 ;
458
481
459
482
boolean needsPrintln = true ;
460
483
while (start != null && start .lessThan (end )) {
461
484
Address val = start .getAddressAt (0 );
462
- out .print (fill (val , formatWidth ));
485
+ out .print (fillHexString (val , formatWidth ));
463
486
needsPrintln = true ;
464
487
width -= formatWidth ;
465
488
start = start .addOffsetTo (formatSize );
466
489
if (width <= formatWidth ) {
467
490
out .println ();
468
491
needsPrintln = false ;
469
492
if (start .lessThan (end )) {
470
- out .print (fill (start , formatWidth ));
493
+ out .print (fillHexString (start , formatWidth ));
471
494
out .print (": " );
472
495
width = line - formatWidth - 2 ;
473
496
}
@@ -482,6 +505,63 @@ public void doit(Tokens t) {
482
505
}
483
506
}
484
507
},
508
+ new Command ("mem" , "mem [-v] { address[/count] | address,address }" , false ) {
509
+ public void doit (Tokens t ) {
510
+ int formatSize = (int )VM .getVM ().getAddressSize ();
511
+ boolean verbose = false ;
512
+ String arg ;
513
+
514
+ if (t .countTokens () == 2 ) {
515
+ arg = t .nextToken ();
516
+ if (arg .equals ("-v" )) {
517
+ verbose = true ;
518
+ } else {
519
+ usage ();
520
+ return ;
521
+ }
522
+ }
523
+ if (t .countTokens () != 1 ) {
524
+ usage ();
525
+ return ;
526
+ }
527
+
528
+ arg = t .nextToken ();
529
+ AddressRange addressRange = parseAddressRange (arg , formatSize );
530
+ if (addressRange == null ) {
531
+ usage ();
532
+ return ;
533
+ }
534
+ Address start = addressRange .getStart ();
535
+ Address end = addressRange .getEnd ();
536
+
537
+ if (verbose ) {
538
+ // Do the equivalent of a findpc on the start address.
539
+ PointerLocation loc = PointerFinder .find (start );
540
+ loc .printOn (out );
541
+ }
542
+
543
+ int formatWidth = formatSize * 8 / 4 + 2 ;
544
+ while (start != null && start .lessThan (end )) {
545
+ out .print (fillHexString (start , formatWidth ));
546
+ out .print (": " );
547
+ Address val = start .getAddressAt (0 );
548
+ out .print (fillHexString (val , formatWidth ));
549
+ if (verbose ) {
550
+ // If we know what this is a pointer to, then print additional information.
551
+ PointerLocation loc = PointerFinder .find (val );
552
+ if (!loc .isUnknown ()) {
553
+ out .print (" " );
554
+ loc .printOn (out , false , false );
555
+ } else {
556
+ out .println ();
557
+ }
558
+ } else {
559
+ out .println ();
560
+ }
561
+ start = start .addOffsetTo (formatSize );
562
+ }
563
+ }
564
+ },
485
565
new Command ("dumpreplaydata" , "dumpreplaydata { <address > | -a | <thread_id> }" , false ) {
486
566
// This is used to dump replay data from ciInstanceKlass, ciMethodData etc
487
567
// default file name is replay.txt, also if java crashes in compiler
0 commit comments