markup_oops.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/perl -w
  2. # Copyright 2008, Intel Corporation
  3. #
  4. # This file is part of the Linux kernel
  5. #
  6. # This program file is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by the
  8. # Free Software Foundation; version 2 of the License.
  9. #
  10. # Authors:
  11. # Arjan van de Ven <arjan@linux.intel.com>
  12. my $vmlinux_name = $ARGV[0];
  13. #
  14. # Step 1: Parse the oops to find the EIP value
  15. #
  16. my $target = "0";
  17. while (<STDIN>) {
  18. if ($_ =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) {
  19. $target = $1;
  20. }
  21. }
  22. if ($target =~ /^f8/) {
  23. print "This script does not work on modules ... \n";
  24. exit;
  25. }
  26. if ($target eq "0") {
  27. print "No oops found!\n";
  28. print "Usage: \n";
  29. print " dmesg | perl scripts/markup_oops.pl vmlinux\n";
  30. exit;
  31. }
  32. my $counter = 0;
  33. my $state = 0;
  34. my $center = 0;
  35. my @lines;
  36. sub InRange {
  37. my ($address, $target) = @_;
  38. my $ad = "0x".$address;
  39. my $ta = "0x".$target;
  40. my $delta = hex($ad) - hex($ta);
  41. if (($delta > -4096) && ($delta < 4096)) {
  42. return 1;
  43. }
  44. return 0;
  45. }
  46. # first, parse the input into the lines array, but to keep size down,
  47. # we only do this for 4Kb around the sweet spot
  48. my $filename;
  49. open(FILE, "objdump -dS $vmlinux_name |") || die "Cannot start objdump";
  50. while (<FILE>) {
  51. my $line = $_;
  52. chomp($line);
  53. if ($state == 0) {
  54. if ($line =~ /^([a-f0-9]+)\:/) {
  55. if (InRange($1, $target)) {
  56. $state = 1;
  57. }
  58. }
  59. } else {
  60. if ($line =~ /^([a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]+)\:/) {
  61. my $val = $1;
  62. if (!InRange($val, $target)) {
  63. last;
  64. }
  65. if ($val eq $target) {
  66. $center = $counter;
  67. }
  68. }
  69. $lines[$counter] = $line;
  70. $counter = $counter + 1;
  71. }
  72. }
  73. close(FILE);
  74. if ($counter == 0) {
  75. print "No matching code found \n";
  76. exit;
  77. }
  78. if ($center == 0) {
  79. print "No matching code found \n";
  80. exit;
  81. }
  82. my $start;
  83. my $finish;
  84. my $codelines = 0;
  85. my $binarylines = 0;
  86. # now we go up and down in the array to find how much we want to print
  87. $start = $center;
  88. while ($start > 1) {
  89. $start = $start - 1;
  90. my $line = $lines[$start];
  91. if ($line =~ /^([a-f0-9]+)\:/) {
  92. $binarylines = $binarylines + 1;
  93. } else {
  94. $codelines = $codelines + 1;
  95. }
  96. if ($codelines > 10) {
  97. last;
  98. }
  99. if ($binarylines > 20) {
  100. last;
  101. }
  102. }
  103. $finish = $center;
  104. $codelines = 0;
  105. $binarylines = 0;
  106. while ($finish < $counter) {
  107. $finish = $finish + 1;
  108. my $line = $lines[$finish];
  109. if ($line =~ /^([a-f0-9]+)\:/) {
  110. $binarylines = $binarylines + 1;
  111. } else {
  112. $codelines = $codelines + 1;
  113. }
  114. if ($codelines > 10) {
  115. last;
  116. }
  117. if ($binarylines > 20) {
  118. last;
  119. }
  120. }
  121. my $i;
  122. my $fulltext = "";
  123. $i = $start;
  124. while ($i < $finish) {
  125. if ($i == $center) {
  126. $fulltext = $fulltext . "*$lines[$i] <----- faulting instruction\n";
  127. } else {
  128. $fulltext = $fulltext . " $lines[$i]\n";
  129. }
  130. $i = $i +1;
  131. }
  132. print $fulltext;