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