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

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [gdb-5.0/] [gdb/] [tui/] [tuiDisassem.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/*
2
   ** tuiDisassem.c
3
   **         This module contains functions for handling disassembly display.
4
 */
5
 
6
 
7
#include "defs.h"
8
#include "symtab.h"
9
#include "breakpoint.h"
10
#include "frame.h"
11
 
12
#include "tui.h"
13
#include "tuiData.h"
14
#include "tuiLayout.h"
15
#include "tuiSourceWin.h"
16
#include "tuiStack.h"
17
 
18
 
19
/*****************************************
20
** STATIC LOCAL FUNCTIONS FORWARD DECLS    **
21
******************************************/
22
 
23
static struct breakpoint *_hasBreak PARAMS ((CORE_ADDR));
24
 
25
 
26
/*****************************************
27
** PUBLIC FUNCTIONS                        **
28
******************************************/
29
 
30
/*
31
   ** tuiSetDisassemContent().
32
   **        Function to set the disassembly window's content.
33
 */
34
TuiStatus
35
#ifdef __STDC__
36
tuiSetDisassemContent (
37
                        struct symtab *s,
38
                        Opaque startAddr)
39
#else
40
tuiSetDisassemContent (s, startAddr)
41
     struct symtab *s;
42
     Opaque startAddr;
43
#endif
44
{
45
  TuiStatus ret = TUI_FAILURE;
46
  struct ui_file *gdb_dis_out;
47
 
48
  if (startAddr != (Opaque) NULL)
49
    {
50
      register int i, desc;
51
 
52
      if ((ret = tuiAllocSourceBuffer (disassemWin)) == TUI_SUCCESS)
53
        {
54
          register int offset = disassemWin->detail.sourceInfo.horizontalOffset;
55
          register int threshold, curLine = 0, lineWidth, maxLines;
56
          CORE_ADDR newpc, pc;
57
          disassemble_info asmInfo;
58
          TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
59
          extern void strcat_address PARAMS ((CORE_ADDR, char *, int));
60
          extern void strcat_address_numeric PARAMS ((CORE_ADDR, int, char *, int));
61
          int curLen = 0;
62
          int tab_len = tuiDefaultTabLen ();
63
 
64
          maxLines = disassemWin->generic.height - 2;   /* account for hilite */
65
          lineWidth = disassemWin->generic.width - 1;
66
          threshold = (lineWidth - 1) + offset;
67
 
68
          /* now init the ui_file structure */
69
          gdb_dis_out = tui_sfileopen (threshold);
70
 
71
          INIT_DISASSEMBLE_INFO_NO_ARCH (asmInfo, gdb_dis_out, (fprintf_ftype) fprintf_filtered);
72
          asmInfo.read_memory_func = dis_asm_read_memory;
73
          asmInfo.memory_error_func = dis_asm_memory_error;
74
 
75
          disassemWin->detail.sourceInfo.startLineOrAddr.addr = startAddr;
76
 
77
          /* Now construct each line */
78
          for (curLine = 0, pc = (CORE_ADDR) startAddr; (curLine < maxLines);)
79
            {
80
              TuiWinElementPtr element = (TuiWinElementPtr) disassemWin->generic.content[curLine];
81
              struct breakpoint *bp;
82
 
83
              print_address (pc, gdb_dis_out);
84
 
85
              curLen = strlen (tui_file_get_strbuf (gdb_dis_out));
86
              i = curLen - ((curLen / tab_len) * tab_len);
87
 
88
              /* adjust buffer length if necessary */
89
              tui_file_adjust_strbuf ((tab_len - i > 0) ? (tab_len - i) : 0, gdb_dis_out);
90
 
91
              /* Add spaces to make the instructions start onthe same column */
92
              while (i < tab_len)
93
                {
94
                  tui_file_get_strbuf (gdb_dis_out)[curLen] = ' ';
95
                  i++;
96
                  curLen++;
97
                }
98
              tui_file_get_strbuf (gdb_dis_out)[curLen] = '\0';
99
 
100
              newpc = pc + ((*tm_print_insn) (pc, &asmInfo));
101
 
102
              /* Now copy the line taking the offset into account */
103
              if (strlen (tui_file_get_strbuf (gdb_dis_out)) > offset)
104
                strcpy (element->whichElement.source.line,
105
                        &(tui_file_get_strbuf (gdb_dis_out)[offset]));
106
              else
107
                element->whichElement.source.line[0] = '\0';
108
              element->whichElement.source.lineOrAddr.addr = (Opaque) pc;
109
              element->whichElement.source.isExecPoint =
110
                (pc == (CORE_ADDR) ((TuiWinElementPtr) locator->content[0])->whichElement.locator.addr);
111
              bp = _hasBreak (pc);
112
              element->whichElement.source.hasBreak =
113
                (bp != (struct breakpoint *) NULL &&
114
                 (!element->whichElement.source.isExecPoint ||
115
                  (bp->disposition != del || bp->hit_count <= 0)));
116
              curLine++;
117
              pc = newpc;
118
              /* reset the buffer to empty */
119
              tui_file_get_strbuf (gdb_dis_out)[0] = '\0';
120
            }
121
          ui_file_delete (gdb_dis_out);
122
          gdb_dis_out = NULL;
123
          disassemWin->generic.contentSize = curLine;
124
          ret = TUI_SUCCESS;
125
        }
126
    }
127
 
128
  return ret;
129
}                               /* tuiSetDisassemContent */
130
 
131
 
132
/*
133
   ** tuiShowDisassem().
134
   **        Function to display the disassembly window with disassembled code.
135
 */
136
void
137
#ifdef __STDC__
138
tuiShowDisassem (
139
                  Opaque startAddr)
140
#else
141
tuiShowDisassem (startAddr)
142
     Opaque startAddr;
143
#endif
144
{
145
  struct symtab *s = find_pc_symtab ((CORE_ADDR) startAddr);
146
  TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
147
 
148
  tuiAddWinToLayout (DISASSEM_WIN);
149
  tuiUpdateSourceWindow (disassemWin, s, startAddr, FALSE);
150
  /*
151
     ** if the focus was in the src win, put it in the asm win, if the
152
     ** source view isn't split
153
   */
154
  if (currentLayout () != SRC_DISASSEM_COMMAND && winWithFocus == srcWin)
155
    tuiSetWinFocusTo (disassemWin);
156
 
157
  return;
158
}                               /* tuiShowDisassem */
159
 
160
 
161
/*
162
   ** tuiShowDisassemAndUpdateSource().
163
   **        Function to display the disassembly window.
164
 */
165
void
166
#ifdef __STDC__
167
tuiShowDisassemAndUpdateSource (
168
                                 Opaque startAddr)
169
#else
170
tuiShowDisassemAndUpdateSource (startAddr)
171
     Opaque startAddr;
172
#endif
173
{
174
  struct symtab_and_line sal;
175
 
176
  tuiShowDisassem (startAddr);
177
  if (currentLayout () == SRC_DISASSEM_COMMAND)
178
    {
179
      TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
180
      /*
181
         ** Update what is in the source window if it is displayed too,
182
         ** note that it follows what is in the disassembly window and visa-versa
183
       */
184
      sal = find_pc_line ((CORE_ADDR) startAddr, 0);
185
      current_source_symtab = sal.symtab;
186
      tuiUpdateSourceWindow (srcWin, sal.symtab, (Opaque) sal.line, TRUE);
187
      tuiUpdateLocatorFilename (sal.symtab->filename);
188
    }
189
 
190
  return;
191
}                               /* tuiShowDisassemAndUpdateSource */
192
 
193
 
194
/*
195
   ** tuiShowDisassemAsIs().
196
   **        Function to display the disassembly window.  This function shows
197
   **        the disassembly as specified by the horizontal offset.
198
 */
199
void
200
#ifdef __STDC__
201
tuiShowDisassemAsIs (
202
                      Opaque addr)
203
#else
204
tuiShowDisassemAsIs (addr)
205
     Opaque addr;
206
#endif
207
{
208
  tuiAddWinToLayout (DISASSEM_WIN);
209
  tuiUpdateSourceWindowAsIs (disassemWin, (struct symtab *) NULL, addr, FALSE);
210
  /*
211
     ** Update what is in the source window if it is displayed too, not that it
212
     ** follows what is in the disassembly window and visa-versa
213
   */
214
  if (currentLayout () == SRC_DISASSEM_COMMAND)
215
    tuiShowSourceContent (srcWin);      /*????  Need to do more? */
216
 
217
  return;
218
}                               /* tuiShowDisassem */
219
 
220
 
221
/*
222
   ** tuiGetBeginAsmAddress().
223
 */
224
Opaque
225
#ifdef __STDC__
226
tuiGetBeginAsmAddress (void)
227
#else
228
tuiGetBeginAsmAddress ()
229
#endif
230
{
231
  TuiGenWinInfoPtr locator;
232
  TuiLocatorElementPtr element;
233
  Opaque addr;
234
 
235
  locator = locatorWinInfoPtr ();
236
  element = &((TuiWinElementPtr) locator->content[0])->whichElement.locator;
237
 
238
  if (element->addr == (Opaque) 0)
239
    {
240
      /*the target is not executing, because the pc is 0 */
241
 
242
      addr = (Opaque) parse_and_eval_address ("main");
243
 
244
      if (addr == (Opaque) 0)
245
        addr = (Opaque) parse_and_eval_address ("MAIN");
246
 
247
    }
248
  else                          /* the target is executing */
249
    addr = element->addr;
250
 
251
  return addr;
252
}                               /* tuiGetBeginAsmAddress */
253
 
254
 
255
/*
256
   ** tuiVerticalDisassemScroll().
257
   **      Scroll the disassembly forward or backward vertically
258
 */
259
void
260
#ifdef __STDC__
261
tuiVerticalDisassemScroll (
262
                            TuiScrollDirection scrollDirection,
263
                            int numToScroll)
264
#else
265
tuiVerticalDisassemScroll (scrollDirection, numToScroll)
266
     TuiScrollDirection scrollDirection;
267
     int numToScroll;
268
#endif
269
{
270
  if (disassemWin->generic.content != (OpaquePtr) NULL)
271
    {
272
      Opaque pc, lowAddr;
273
      TuiWinContent content;
274
      struct symtab *s;
275
 
276
      content = (TuiWinContent) disassemWin->generic.content;
277
      if (current_source_symtab == (struct symtab *) NULL)
278
        s = find_pc_symtab (selected_frame->pc);
279
      else
280
        s = current_source_symtab;
281
 
282
      pc = content[0]->whichElement.source.lineOrAddr.addr;
283
      if (find_pc_partial_function ((CORE_ADDR) pc,
284
                                    (char **) NULL,
285
                                    (CORE_ADDR *) & lowAddr,
286
                                    (CORE_ADDR) NULL) == 0)
287
        error ("No function contains prgram counter for selected frame.\n");
288
      else
289
        {
290
          register int line = 0;
291
          register Opaque newLow;
292
          bfd_byte buffer[4];
293
 
294
          newLow = pc;
295
          if (scrollDirection == FORWARD_SCROLL)
296
            {
297
              for (; line < numToScroll; line++)
298
                newLow += sizeof (bfd_getb32 (buffer));
299
            }
300
          else
301
            {
302
              for (; newLow >= (Opaque) 0 && line < numToScroll; line++)
303
                newLow -= sizeof (bfd_getb32 (buffer));
304
            }
305
          tuiUpdateSourceWindowAsIs (disassemWin, s, newLow, FALSE);
306
        }
307
    }
308
 
309
  return;
310
}                               /* tuiVerticalDisassemScroll */
311
 
312
 
313
 
314
/*****************************************
315
** STATIC LOCAL FUNCTIONS                 **
316
******************************************/
317
/*
318
   ** _hasBreak().
319
   **      Answer whether there is a break point at the input line in the
320
   **      source file indicated
321
 */
322
static struct breakpoint *
323
#ifdef __STDC__
324
_hasBreak (
325
            CORE_ADDR addr)
326
#else
327
_hasBreak (addr)
328
     CORE_ADDR addr;
329
#endif
330
{
331
  struct breakpoint *bpWithBreak = (struct breakpoint *) NULL;
332
  struct breakpoint *bp;
333
  extern struct breakpoint *breakpoint_chain;
334
 
335
 
336
  for (bp = breakpoint_chain;
337
       (bp != (struct breakpoint *) NULL &&
338
        bpWithBreak == (struct breakpoint *) NULL);
339
       bp = bp->next)
340
    if (addr == bp->address)
341
      bpWithBreak = bp;
342
 
343
  return bpWithBreak;
344
}                               /* _hasBreak */

powered by: WebSVN 2.1.0

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