winedbg: gdbproxy: Quietly handle qSupported and qTStatus.
[wine] / programs / winedbg / memory.c
1 /*
2  * Debugger memory handling
3  *
4  * Copyright 1993 Eric Youngdale
5  * Copyright 1995 Alexandre Julliard
6  * Copyright 2000-2005 Eric Pouech
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library 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 GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdio.h>
29
30 #include "debugger.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
34
35 void* be_cpu_linearize(HANDLE hThread, const ADDRESS64* addr)
36 {
37     assert(addr->Mode == AddrModeFlat);
38     return (void*)(DWORD_PTR)addr->Offset;
39 }
40
41 unsigned be_cpu_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* addr, 
42                            unsigned seg, unsigned long offset)
43 {
44     addr->Mode    = AddrModeFlat;
45     addr->Segment = 0; /* don't need segment */
46     addr->Offset  = offset;
47     return TRUE;
48 }
49
50 void* memory_to_linear_addr(const ADDRESS64* addr)
51 {
52     return be_cpu->linearize(dbg_curr_thread->handle, addr);
53 }
54
55 BOOL memory_get_current_pc(ADDRESS64* addr)
56 {
57     assert(be_cpu->get_addr);
58     return be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context, 
59                             be_cpu_addr_pc, addr);
60 }
61
62 BOOL memory_get_current_stack(ADDRESS64* addr)
63 {
64     assert(be_cpu->get_addr);
65     return be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context, 
66                             be_cpu_addr_stack, addr);
67 }
68
69 BOOL memory_get_current_frame(ADDRESS64* addr)
70 {
71     assert(be_cpu->get_addr);
72     return be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context, 
73                             be_cpu_addr_frame, addr);
74 }
75
76 static void     memory_report_invalid_addr(const void* addr)
77 {
78     ADDRESS64   address;
79
80     address.Mode    = AddrModeFlat;
81     address.Segment = 0;
82     address.Offset  = (unsigned long)addr;
83     dbg_printf("*** Invalid address ");
84     print_address(&address, FALSE);
85     dbg_printf(" ***\n");
86 }
87
88 /***********************************************************************
89  *           memory_read_value
90  *
91  * Read a memory value.
92  */
93 BOOL memory_read_value(const struct dbg_lvalue* lvalue, DWORD size, void* result)
94 {
95     BOOL ret = FALSE;
96
97     if (lvalue->cookie == DLV_TARGET)
98     {
99         void*   linear = memory_to_linear_addr(&lvalue->addr);
100         if (!(ret = dbg_read_memory(linear, result, size)))
101             memory_report_invalid_addr(linear);
102     }
103     else
104     {
105         if (lvalue->addr.Offset)
106         {
107             memcpy(result, (void*)(DWORD_PTR)lvalue->addr.Offset, size);
108             ret = TRUE;
109         }
110     }
111     return ret;
112 }
113
114 /***********************************************************************
115  *           memory_write_value
116  *
117  * Store a value in memory.
118  */
119 BOOL memory_write_value(const struct dbg_lvalue* lvalue, DWORD size, void* value)
120 {
121     BOOL        ret = TRUE;
122     DWORD64     os;
123
124     if (!types_get_info(&lvalue->type, TI_GET_LENGTH, &os)) return FALSE;
125     if (size != os)
126     {
127         dbg_printf("Size mismatch in memory_write_value, got %u from type while expecting %u\n",
128                    (DWORD)os, size);
129         return FALSE;
130     }
131
132     /* FIXME: only works on little endian systems */
133     if (lvalue->cookie == DLV_TARGET)
134     {
135         void*       linear = memory_to_linear_addr(&lvalue->addr);
136         if (!(ret = dbg_write_memory(linear, value, size)))
137             memory_report_invalid_addr(linear);
138     }
139     else 
140     {
141         memcpy((void*)(DWORD_PTR)lvalue->addr.Offset, value, size);
142     }
143     return ret;
144 }
145
146 /***********************************************************************
147  *           memory_examine
148  *
149  * Implementation of the 'x' command.
150  */
151 void memory_examine(const struct dbg_lvalue *lvalue, int count, char format)
152 {
153     int                 i;
154     char                buffer[256];
155     ADDRESS64           addr;
156     void               *linear;
157
158     types_extract_as_address(lvalue, &addr);
159     linear = memory_to_linear_addr(&addr);
160
161     if (format != 'i' && count > 1)
162     {
163         print_address(&addr, FALSE);
164         dbg_printf(": ");
165     }
166
167     switch (format)
168     {
169     case 'u':
170         if (count == 1) count = 256;
171         memory_get_string(dbg_curr_process, linear, 
172                           TRUE, TRUE, buffer, min(count, sizeof(buffer)));
173         dbg_printf("%s\n", buffer);
174         return;
175     case 's':
176         if (count == 1) count = 256;
177         memory_get_string(dbg_curr_process, linear,
178                           TRUE, FALSE, buffer, min(count, sizeof(buffer)));
179         dbg_printf("%s\n", buffer);
180         return;
181     case 'i':
182         while (count-- && memory_disasm_one_insn(&addr));
183         return;
184     case 'g':
185         while (count--)
186         {
187             GUID guid;
188             if (!dbg_read_memory(linear, &guid, sizeof(guid)))
189             {
190                 memory_report_invalid_addr(linear);
191                 break;
192             }
193             dbg_printf("{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
194                        guid.Data1, guid.Data2, guid.Data3,
195                        guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
196                        guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
197             linear = (char*)linear + sizeof(guid);
198             addr.Offset += sizeof(guid);
199             if (count)
200             {
201                 print_address(&addr, FALSE);
202                 dbg_printf(": ");
203             }
204         }
205         return;
206
207 #define DO_DUMP2(_t,_l,_f,_vv) {                                        \
208             _t _v;                                                      \
209             for (i = 0; i < count; i++) {                               \
210                 if (!dbg_read_memory(linear, &_v, sizeof(_t)))          \
211                 { memory_report_invalid_addr(linear); break; }          \
212                 dbg_printf(_f, (_vv));                                  \
213                 addr.Offset += sizeof(_t);                              \
214                 linear = (char*)linear + sizeof(_t);                    \
215                 if ((i % (_l)) == (_l) - 1 && i != count - 1)           \
216                 {                                                       \
217                     dbg_printf("\n");                                   \
218                     print_address(&addr, FALSE);                        \
219                     dbg_printf(": ");                                   \
220                 }                                                       \
221             }                                                           \
222             dbg_printf("\n");                                           \
223         }
224 #define DO_DUMP(_t,_l,_f) DO_DUMP2(_t,_l,_f,_v)
225
226     case 'x': DO_DUMP(int, 4, " %8.8x"); break;
227     case 'd': DO_DUMP(unsigned int, 4, " %4.4d"); break;
228     case 'w': DO_DUMP(unsigned short, 8, " %04x"); break;
229     case 'a':
230         if (sizeof(DWORD_PTR) == 4)
231         {
232             DO_DUMP(DWORD_PTR, 4, " %8.8lx");
233         }
234         else
235         {
236             DO_DUMP(DWORD_PTR, 2, " %16.16lx");
237         }
238         break;
239     case 'c': DO_DUMP2(char, 32, " %c", (_v < 0x20) ? ' ' : _v); break;
240     case 'b': DO_DUMP2(char, 16, " %02x", (_v) & 0xff); break;
241     }
242 }
243
244 BOOL memory_get_string(struct dbg_process* pcs, void* addr, BOOL in_debuggee,
245                        BOOL unicode, char* buffer, int size)
246 {
247     SIZE_T      sz;
248     WCHAR*      buffW;
249
250     buffer[0] = 0;
251     if (!addr) return FALSE;
252     if (in_debuggee)
253     {
254         BOOL ret;
255
256         if (!unicode) ret = pcs->process_io->read(pcs->handle, addr, buffer, size, &sz);
257         else
258         {
259             buffW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
260             ret = pcs->process_io->read(pcs->handle, addr, buffW, size * sizeof(WCHAR), &sz);
261             WideCharToMultiByte(CP_ACP, 0, buffW, sz / sizeof(WCHAR), buffer, size,
262                                 NULL, NULL);
263             HeapFree(GetProcessHeap(), 0, buffW);
264         }
265         if (size) buffer[size-1] = 0;
266         return ret;
267     }
268     else
269     {
270         lstrcpynA(buffer, addr, size);
271     }
272     return TRUE;
273 }
274
275 BOOL memory_get_string_indirect(struct dbg_process* pcs, void* addr, BOOL unicode, WCHAR* buffer, int size)
276 {
277     void*       ad;
278     SIZE_T      sz;
279
280     buffer[0] = 0;
281     if (addr &&
282         pcs->process_io->read(pcs->handle, addr, &ad, sizeof(ad), &sz) && sz == sizeof(ad) && ad)
283     {
284         LPSTR buff;
285         BOOL ret;
286
287         if (unicode)
288             ret = pcs->process_io->read(pcs->handle, ad, buffer, size * sizeof(WCHAR), &sz) && sz != 0;
289         else
290         {
291             if ((buff = HeapAlloc(GetProcessHeap(), 0, size)))
292             {
293                 ret = pcs->process_io->read(pcs->handle, ad, buff, size, &sz) && sz != 0;
294                 MultiByteToWideChar(CP_ACP, 0, buff, sz, buffer, size);
295                 HeapFree(GetProcessHeap(), 0, buff);
296             }
297             else ret = FALSE;
298         }
299         if (size) buffer[size-1] = 0;
300         return ret;
301     }
302     return FALSE;
303 }
304
305 /*
306  * Convert an address offset to hex string. If mode == 32, treat offset as
307  * 32 bits (discard upper 32 bits), if mode == 64 use all 64 bits, if mode == 0
308  * treat as either 32 or 64 bits, depending on whether we're running as
309  * Wine32 or Wine64.
310  */
311 char* memory_offset_to_string(char *str, DWORD64 offset, unsigned mode)
312 {
313     if (mode != 32 && mode != 64)
314     {
315 #ifdef _WIN64
316         mode = 64;
317 #else
318         mode = 32;
319 #endif
320     }
321
322     if (mode == 32)
323         sprintf(str, "0x%08x", (unsigned int) offset);
324     else
325         sprintf(str, "0x%08x%08x", (unsigned int)(offset >> 32),
326                 (unsigned int)offset);
327
328     return str;
329 }
330
331 static void dbg_print_longlong(LONGLONG sv, BOOL is_signed)
332 {
333     char      tmp[24], *ptr = tmp + sizeof(tmp) - 1;
334     ULONGLONG uv, div;
335     *ptr = '\0';
336     if (is_signed && sv < 0)    uv = -sv;
337     else                        { uv = sv; is_signed = FALSE; }
338     for (div = 10; uv; div *= 10, uv /= 10)
339         *--ptr = '0' + (uv % 10);
340     if (ptr == tmp + sizeof(tmp) - 1) *--ptr = '0';
341     if (is_signed) *--ptr = '-';
342     dbg_printf("%s", ptr);
343 }
344
345 static void dbg_print_hex(ULONGLONG sv)
346 {
347     if (!sv)
348     {
349         dbg_printf("0");
350         return;
351     }
352
353     if (sv >> 32)
354         dbg_printf("0x%lx%08lx", (unsigned long)(sv >> 32), (unsigned long)sv);
355     else
356         dbg_printf("0x%04lx", (unsigned long)sv);
357 }
358
359 static void print_typed_basic(const struct dbg_lvalue* lvalue)
360 {
361     LONGLONG            val_int;
362     void*               val_ptr;
363     long double         val_real;
364     DWORD64             size64;
365     DWORD               tag, size, count, bt;
366     struct dbg_type     type = lvalue->type;
367     struct dbg_type     sub_type;
368     struct dbg_lvalue   sub_lvalue;
369
370     if (!types_get_real_type(&type, &tag)) return;
371
372     switch (tag)
373     {
374     case SymTagBaseType:
375         if (!types_get_info(&type, TI_GET_LENGTH, &size64) ||
376             !types_get_info(&type, TI_GET_BASETYPE, &bt))
377         {
378             WINE_ERR("Couldn't get information\n");
379             RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
380         }
381         size = (DWORD)size64;
382         switch (bt)
383         {
384         case btInt:
385         case btLong:
386             if (!be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return;
387             if (size == 1) goto print_char;
388             dbg_print_hex(val_int);
389             break;
390         case btUInt:
391         case btULong:
392             if (!be_cpu->fetch_integer(lvalue, size, FALSE, &val_int)) return;
393             dbg_print_hex(val_int);
394             break;
395         case btFloat:
396             if (!be_cpu->fetch_float(lvalue, size, &val_real)) return;
397             dbg_printf("%Lf", val_real);
398             break;
399         case btChar:
400             if (!be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return;
401             /* FIXME: should do the same for a Unicode character (size == 2) */
402         print_char:
403             if (size == 1 && (val_int < 0x20 || val_int > 0x80))
404                 dbg_printf("%d", (int)val_int);
405             else if (size == 2)
406             {
407                 WCHAR   wch = (WCHAR)val_int;
408                 dbg_outputW(&wch, 1);
409             }
410             else
411                 dbg_printf("'%c'", (char)val_int);
412             break;
413         case btBool:
414             if (!be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return;
415             dbg_printf("%s", val_int ? "true" : "false");
416             break;
417         default:
418             WINE_FIXME("Unsupported basetype %u\n", bt);
419             break;
420         }
421         break;
422     case SymTagPointerType:
423         if (!types_array_index(lvalue, 0, &sub_lvalue))
424         {
425             dbg_printf("Internal symbol error: unable to access memory location %p",
426                        memory_to_linear_addr(&lvalue->addr));
427             break;
428         }
429         val_ptr = memory_to_linear_addr(&sub_lvalue.addr);
430         if (types_get_real_type(&sub_lvalue.type, &tag) && tag == SymTagBaseType &&
431             types_get_info(&sub_lvalue.type, TI_GET_BASETYPE, &bt) &&
432             types_get_info(&sub_lvalue.type, TI_GET_LENGTH, &size64))
433         {
434             char    buffer[1024];
435
436             if (!val_ptr) dbg_printf("0x0");
437             else if (((bt == btChar || bt == btInt) && size64 == 1) || (bt == btUInt && size64 == 2))
438             {
439                 if (memory_get_string(dbg_curr_process, val_ptr, sub_lvalue.cookie == DLV_TARGET,
440                                       size64 == 2, buffer, sizeof(buffer)))
441                     dbg_printf("\"%s\"", buffer);
442                 else
443                     dbg_printf("*** invalid address %p ***", val_ptr);
444                 break;
445             }
446         }
447         dbg_printf("%p", val_ptr);
448         break;
449     case SymTagArrayType:
450     case SymTagUDT:
451         if (!memory_read_value(lvalue, sizeof(val_ptr), &val_ptr)) return;
452         dbg_printf("%p", val_ptr);
453         break;
454     case SymTagEnum:
455         {
456             BOOL        ok = FALSE;
457
458             /* FIXME: it depends on underlying type for enums 
459              * (not supported yet in dbghelp)
460              * Assuming 4 as for an int
461              */
462             if (!be_cpu->fetch_integer(lvalue, 4, TRUE, &val_int)) return;
463
464             if (types_get_info(&type, TI_GET_CHILDRENCOUNT, &count))
465             {
466                 char                    buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
467                 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
468                 WCHAR*                  ptr;
469                 char                    tmp[256];
470                 VARIANT                 variant;
471                 int                     i;
472
473                 fcp->Start = 0;
474                 while (count)
475                 {
476                     fcp->Count = min(count, 256);
477                     if (types_get_info(&type, TI_FINDCHILDREN, fcp))
478                     {
479                         sub_type.module = type.module;
480                         for (i = 0; i < min(fcp->Count, count); i++)
481                         {
482                             sub_type.id = fcp->ChildId[i];
483                             if (!types_get_info(&sub_type, TI_GET_VALUE, &variant)) 
484                                 continue;
485                             switch (variant.n1.n2.vt)
486                             {
487                             case VT_I4: ok = (val_int == variant.n1.n2.n3.lVal); break;
488                             default: WINE_FIXME("Unsupported variant type (%u)\n", variant.n1.n2.vt);
489                             }
490                             if (ok)
491                             {
492                                 ptr = NULL;
493                                 types_get_info(&sub_type, TI_GET_SYMNAME, &ptr);
494                                 if (!ptr) continue;
495                                 WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
496                                 HeapFree(GetProcessHeap(), 0, ptr);
497                                 dbg_printf("%s", tmp);
498                                 count = 0; /* so that we'll get away from outter loop */
499                                 break;
500                             }
501                         }
502                     }
503                     count -= min(count, 256);
504                     fcp->Start += 256;
505                 }
506             }
507             if (!ok) dbg_print_longlong(val_int, TRUE);
508         }
509         break;
510     default:
511         WINE_FIXME("Unsupported tag %u\n", tag);
512         break;
513     }
514 }
515
516 /***********************************************************************
517  *           print_basic
518  *
519  * Implementation of the 'print' command.
520  */
521 void print_basic(const struct dbg_lvalue* lvalue, char format)
522 {
523     if (lvalue->type.id == dbg_itype_none)
524     {
525         dbg_printf("Unable to evaluate expression\n");
526         return;
527     }
528
529     if (format != 0)
530     {
531         unsigned size;
532         LONGLONG res = types_extract_as_longlong(lvalue, &size);
533         DWORD hi;
534         WCHAR wch;
535
536         /* FIXME: this implies i386 byte ordering */
537         switch (format)
538         {
539         case 'x':
540             hi = (ULONG64)res >> 32;
541             if (size == 8 && hi)
542                 dbg_printf("0x%x%08x", hi, (DWORD)res);
543             else
544                 dbg_printf("0x%x", (DWORD)res);
545             return;
546
547         case 'd':
548             dbg_print_longlong(res, TRUE);
549             dbg_printf("\n");
550             return;
551
552         case 'c':
553             dbg_printf("%d = '%c'", (char)(res & 0xff), (char)(res & 0xff));
554             return;
555
556         case 'u':
557             wch = (WCHAR)(res & 0xFFFF);
558             dbg_printf("%d = '", wch);
559             dbg_outputW(&wch, 1);
560             dbg_printf("'");
561             return;
562
563         case 'i':
564         case 's':
565         case 'w':
566         case 'b':
567             dbg_printf("Format specifier '%c' is meaningless in 'print' command\n", format);
568         }
569     }
570     if (lvalue->type.id == dbg_itype_segptr)
571     {
572         dbg_print_longlong(types_extract_as_longlong(lvalue, NULL), TRUE);
573         dbg_printf("\n");
574     }
575     else print_typed_basic(lvalue);
576 }
577
578 void print_bare_address(const ADDRESS64* addr)
579 {
580     char hexbuf[MAX_OFFSET_TO_STR_LEN];
581
582     switch (addr->Mode)
583     {
584     case AddrModeFlat: 
585         dbg_printf("%s", memory_offset_to_string(hexbuf, addr->Offset, 0)); 
586         break;
587     case AddrModeReal:
588     case AddrMode1616:
589         dbg_printf("0x%04x:0x%04x", addr->Segment, (unsigned) addr->Offset);
590         break;
591     case AddrMode1632:
592         dbg_printf("0x%04x:%s", addr->Segment,
593                    memory_offset_to_string(hexbuf, addr->Offset, 32));
594         break;
595     default:
596         dbg_printf("Unknown mode %x\n", addr->Mode);
597         break;
598     }
599 }
600
601 /***********************************************************************
602  *           print_address
603  *
604  * Print an 16- or 32-bit address, with the nearest symbol if any.
605  */
606 void print_address(const ADDRESS64* addr, BOOLEAN with_line)
607 {
608     char                buffer[sizeof(SYMBOL_INFO) + 256];
609     SYMBOL_INFO*        si = (SYMBOL_INFO*)buffer;
610     void*               lin = memory_to_linear_addr(addr);
611     DWORD64             disp64;
612     DWORD               disp;
613
614     print_bare_address(addr);
615
616     si->SizeOfStruct = sizeof(*si);
617     si->MaxNameLen   = 256;
618     if (!SymFromAddr(dbg_curr_process->handle, (DWORD_PTR)lin, &disp64, si)) return;
619     dbg_printf(" %s", si->Name);
620     if (disp64) dbg_printf("+0x%lx", (DWORD_PTR)disp64);
621     if (with_line)
622     {
623         IMAGEHLP_LINE64             il;
624         IMAGEHLP_MODULE             im;
625
626         il.SizeOfStruct = sizeof(il);
627         if (SymGetLineFromAddr64(dbg_curr_process->handle, (DWORD_PTR)lin, &disp, &il))
628             dbg_printf(" [%s:%u]", il.FileName, il.LineNumber);
629         im.SizeOfStruct = sizeof(im);
630         if (SymGetModuleInfo(dbg_curr_process->handle, (DWORD_PTR)lin, &im))
631             dbg_printf(" in %s", im.ModuleName);
632     }
633 }
634
635 BOOL memory_disasm_one_insn(ADDRESS64* addr)
636 {
637     char        ch;
638
639     print_address(addr, TRUE);
640     dbg_printf(": ");
641     if (!dbg_read_memory(memory_to_linear_addr(addr), &ch, sizeof(ch)))
642     {
643         dbg_printf("-- no code accessible --\n");
644         return FALSE;
645     }
646     be_cpu->disasm_one_insn(addr, TRUE);
647     dbg_printf("\n");
648     return TRUE;
649 }
650
651 void memory_disassemble(const struct dbg_lvalue* xstart, 
652                         const struct dbg_lvalue* xend, int instruction_count)
653 {
654     static ADDRESS64 last = {0,0,0};
655     int stop = 0;
656     int i;
657
658     if (!xstart && !xend) 
659     {
660         if (!last.Segment && !last.Offset) memory_get_current_pc(&last);
661     }
662     else
663     {
664         if (xstart)
665             types_extract_as_address(xstart, &last);
666         if (xend) 
667             stop = types_extract_as_integer(xend);
668     }
669     for (i = 0; (instruction_count == 0 || i < instruction_count)  &&
670                 (stop == 0 || last.Offset <= stop); i++)
671         memory_disasm_one_insn(&last);
672 }
673
674 BOOL memory_get_register(DWORD regno, DWORD_PTR** value, char* buffer, int len)
675 {
676     const struct dbg_internal_var*  div;
677
678     /* negative register values are wine's dbghelp hacks
679      * see dlls/dbghelp/dbghelp_private.h for the details
680      */
681     switch (regno)
682     {
683     case -1:
684         if (buffer) snprintf(buffer, len, "<internal error>");
685         return FALSE;
686     case -2:
687         if (buffer) snprintf(buffer, len, "<couldn't compute location>");
688         return FALSE;
689     case -3:
690         if (buffer) snprintf(buffer, len, "<is not available>");
691         return FALSE;
692     case -4:
693         if (buffer) snprintf(buffer, len, "<couldn't read memory>");
694         return FALSE;
695     case -5:
696         if (buffer) snprintf(buffer, len, "<has been optimized away by compiler>");
697         return FALSE;
698     }
699
700     for (div = be_cpu->context_vars; div->name; div++)
701     {
702         if (div->val == regno)
703         {
704             if (!stack_get_register_frame(div, value))
705             {
706                 if (buffer) snprintf(buffer, len, "<register %s not accessible in this frame>", div->name);
707                 return FALSE;
708             }
709
710             if (buffer) lstrcpynA(buffer, div->name, len);
711             return TRUE;
712         }
713     }
714     if (buffer) snprintf(buffer, len, "<unknown register %u>", regno);
715     return FALSE;
716 }