summaryrefslogtreecommitdiff
path: root/resources/gdb/debug.pl
blob: 5bca69a720e85e4819a425ff1bfc014e403acdb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Perl script to easily launch AT91 debug sessions.

use File::Basename;

# List of supported boards
my @boards = ("at91sam7se-ek",
             "at91sam9260-ek",
             "at91sam9261-ek",
             "at91sam9263-ek",
             "at91sam9rl-ek",
             "at91sam9xe-ek",
             "at91sam9g20-ek",
             "at91sam9m10-ek",
             "at91cap9-dk",
             "at91cap9-stk"
             );

# Check that an argument has been provided
if (!@ARGV[0]) {

   print("Usage: " . basename($0) . " <elf-file>\n");
   exit(1);
}

# Parse file name
my $file = @ARGV[0];
my $script = "";
my $gdb = dirname($0);

# Check #2: this must be an elf file
if ($file !~ m/.*.elf/i) {

   print(".elf file expected.\n");
   exit(2);
}

# Check #1: 'sdram' or 'ddram' or 'bcram' token in filename
if (($file =~ m/.*sdram.*/i) or ($file =~ m/.*ddram.*/i) or ($file =~ m/.*bcram.*/i) or ($file =~ m/.*sam9.*/i) or ($file =~ m/.*cap9.*/i) ) {

   # Find board basename
   foreach $board (@boards) {

      if (index($file, $board) != -1) {

         $script = "$gdb\\$board";
      }
   }

   # Add -ek-mck or -ek-sdram depending on need
   if ($file =~ m/.*sdram.*/i) {

      $script .= "-sdram.gdb";
   }
   elsif ($file =~ m/.*ddram.*/i) {

      $script .= "-ddram.gdb";
   }
   elsif ($file =~ m/.*bcram.*/i) {

      $script .= "-bcram.gdb";
   }   
   else {

      $script .= "-sram.gdb";
   }
}

# Create command file to define "reset" command
open(CMD, ">cmd.gdb") or die("Could not create command file:\n$!");
print(CMD "define reset\n");
print(CMD "    target remote localhost:2331\n");
print(CMD "    monitor reset\n");
if ($script) {

   print(CMD "    source $script\n");
}
print(CMD "    load\n");
print(CMD "end");
close(CMD);

# Launch GDB
$pid = fork();
if ($pid == 0) {

   exec("arm-none-eabi-gdb -x cmd.gdb -ex \"reset\" $file");
}
else {

   $SIG{INT} = 'IGNORE';
   $res = waitpid($pid, 0);
}
print("Done\n");
unlink("cmd.gdb");
personal git repositories of Harald Welte. Your mileage may vary