OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [gdb/] [mi/] [mi-cmd-disas.c] - Blame information for rev 861

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
/* MI Command Set - disassemble commands.
2
   Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009, 2010
3
   Free Software Foundation, Inc.
4
   Contributed by Cygnus Solutions (a Red Hat company).
5
 
6
   This file is part of GDB.
7
 
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
12
 
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
 
21
#include "defs.h"
22
#include "arch-utils.h"
23
#include "target.h"
24
#include "value.h"
25
#include "mi-cmds.h"
26
#include "mi-getopt.h"
27
#include "gdb_string.h"
28
#include "ui-out.h"
29
#include "disasm.h"
30
 
31
/* The arguments to be passed on the command line and parsed here are:
32
 
33
   either:
34
 
35
   START-ADDRESS: address to start the disassembly at.
36
   END-ADDRESS: address to end the disassembly at.
37
 
38
   or:
39
 
40
   FILENAME: The name of the file where we want disassemble from.
41
   LINE: The line around which we want to disassemble. It will
42
   disassemble the function that contins that line.
43
   HOW_MANY: Number of disassembly lines to display. In mixed mode, it
44
   is the number of disassembly lines only, not counting the source
45
   lines.
46
 
47
   always required:
48
 
49
   MODE: 0 or 1 for disassembly only, or mixed source and disassembly,
50
   respectively. */
51
void
52
mi_cmd_disassemble (char *command, char **argv, int argc)
53
{
54
  struct gdbarch *gdbarch = get_current_arch ();
55
  CORE_ADDR start;
56
 
57
  int mixed_source_and_assembly;
58
  struct symtab *s;
59
 
60
  /* Which options have we processed ... */
61
  int file_seen = 0;
62
  int line_seen = 0;
63
  int num_seen = 0;
64
  int start_seen = 0;
65
  int end_seen = 0;
66
 
67
  /* ... and their corresponding value. */
68
  char *file_string = NULL;
69
  int line_num = -1;
70
  int how_many = -1;
71
  CORE_ADDR low = 0;
72
  CORE_ADDR high = 0;
73
 
74
  /* Options processing stuff. */
75
  int optind = 0;
76
  char *optarg;
77
  enum opt
78
  {
79
    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
80
  };
81
  static struct mi_opt opts[] = {
82
    {"f", FILE_OPT, 1},
83
    {"l", LINE_OPT, 1},
84
    {"n", NUM_OPT, 1},
85
    {"s", START_OPT, 1},
86
    {"e", END_OPT, 1},
87
    { 0, 0, 0 }
88
  };
89
 
90
  /* Get the options with their arguments. Keep track of what we
91
     encountered. */
92
  while (1)
93
    {
94
      int opt = mi_getopt ("mi_cmd_disassemble", argc, argv, opts,
95
                           &optind, &optarg);
96
      if (opt < 0)
97
        break;
98
      switch ((enum opt) opt)
99
        {
100
        case FILE_OPT:
101
          file_string = xstrdup (optarg);
102
          file_seen = 1;
103
          break;
104
        case LINE_OPT:
105
          line_num = atoi (optarg);
106
          line_seen = 1;
107
          break;
108
        case NUM_OPT:
109
          how_many = atoi (optarg);
110
          num_seen = 1;
111
          break;
112
        case START_OPT:
113
          low = parse_and_eval_address (optarg);
114
          start_seen = 1;
115
          break;
116
        case END_OPT:
117
          high = parse_and_eval_address (optarg);
118
          end_seen = 1;
119
          break;
120
        }
121
    }
122
  argv += optind;
123
  argc -= optind;
124
 
125
  /* Allow only filename + linenum (with how_many which is not
126
     required) OR start_addr + and_addr */
127
 
128
  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen)
129
        || (line_seen && file_seen && !num_seen && !start_seen && !end_seen)
130
        || (!line_seen && !file_seen && !num_seen && start_seen && end_seen)))
131
    error
132
      ("mi_cmd_disassemble: Usage: ( [-f filename -l linenum [-n howmany]] | [-s startaddr -e endaddr]) [--] mixed_mode.");
133
 
134
  if (argc != 1)
135
    error
136
      ("mi_cmd_disassemble: Usage: [-f filename -l linenum [-n howmany]] [-s startaddr -e endaddr] [--] mixed_mode.");
137
 
138
  mixed_source_and_assembly = atoi (argv[0]);
139
  if ((mixed_source_and_assembly != 0) && (mixed_source_and_assembly != 1))
140
    error (_("mi_cmd_disassemble: Mixed_mode argument must be 0 or 1."));
141
 
142
 
143
  /* We must get the function beginning and end where line_num is
144
     contained. */
145
 
146
  if (line_seen && file_seen)
147
    {
148
      s = lookup_symtab (file_string);
149
      if (s == NULL)
150
        error (_("mi_cmd_disassemble: Invalid filename."));
151
      if (!find_line_pc (s, line_num, &start))
152
        error (_("mi_cmd_disassemble: Invalid line number"));
153
      if (find_pc_partial_function (start, NULL, &low, &high) == 0)
154
        error (_("mi_cmd_disassemble: No function contains specified address"));
155
    }
156
 
157
  gdb_disassembly (gdbarch, uiout,
158
                   file_string,
159
                   mixed_source_and_assembly? DISASSEMBLY_SOURCE : 0,
160
                   how_many, low, high);
161
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.