]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
Merge ^/head r304236 through r304536.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFFormValue.cpp
1 //===-- DWARFFormValue.cpp --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include <assert.h>
11
12 #include "lldb/Core/dwarf.h"
13 #include "lldb/Core/Stream.h"
14
15 #include "DWARFFormValue.h"
16 #include "DWARFCompileUnit.h"
17
18 class DWARFCompileUnit;
19
20 using namespace lldb_private;
21
22
23 static uint8_t g_form_sizes_addr4[] = 
24 {
25     0, // 0x00 unused
26     4, // 0x01 DW_FORM_addr
27     0, // 0x02 unused
28     0, // 0x03 DW_FORM_block2
29     0, // 0x04 DW_FORM_block4
30     2, // 0x05 DW_FORM_data2
31     4, // 0x06 DW_FORM_data4
32     8, // 0x07 DW_FORM_data8
33     0, // 0x08 DW_FORM_string
34     0, // 0x09 DW_FORM_block
35     0, // 0x0a DW_FORM_block1
36     1, // 0x0b DW_FORM_data1
37     1, // 0x0c DW_FORM_flag
38     0, // 0x0d DW_FORM_sdata
39     4, // 0x0e DW_FORM_strp
40     0, // 0x0f DW_FORM_udata
41     0, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
42     1, // 0x11 DW_FORM_ref1
43     2, // 0x12 DW_FORM_ref2
44     4, // 0x13 DW_FORM_ref4
45     8, // 0x14 DW_FORM_ref8
46     0, // 0x15 DW_FORM_ref_udata
47     0, // 0x16 DW_FORM_indirect
48     4, // 0x17 DW_FORM_sec_offset
49     0, // 0x18 DW_FORM_exprloc
50     0, // 0x19 DW_FORM_flag_present
51     0, // 0x1a
52     0, // 0x1b
53     0, // 0x1c
54     0, // 0x1d
55     0, // 0x1e
56     0, // 0x1f
57     8, // 0x20 DW_FORM_ref_sig8
58
59 };
60
61 static uint8_t
62 g_form_sizes_addr8[] = 
63 {
64     0, // 0x00 unused
65     8, // 0x01 DW_FORM_addr
66     0, // 0x02 unused
67     0, // 0x03 DW_FORM_block2
68     0, // 0x04 DW_FORM_block4
69     2, // 0x05 DW_FORM_data2
70     4, // 0x06 DW_FORM_data4
71     8, // 0x07 DW_FORM_data8
72     0, // 0x08 DW_FORM_string
73     0, // 0x09 DW_FORM_block
74     0, // 0x0a DW_FORM_block1
75     1, // 0x0b DW_FORM_data1
76     1, // 0x0c DW_FORM_flag
77     0, // 0x0d DW_FORM_sdata
78     4, // 0x0e DW_FORM_strp
79     0, // 0x0f DW_FORM_udata
80     0, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
81     1, // 0x11 DW_FORM_ref1
82     2, // 0x12 DW_FORM_ref2
83     4, // 0x13 DW_FORM_ref4
84     8, // 0x14 DW_FORM_ref8
85     0, // 0x15 DW_FORM_ref_udata
86     0, // 0x16 DW_FORM_indirect
87     4, // 0x17 DW_FORM_sec_offset
88     0, // 0x18 DW_FORM_exprloc
89     0, // 0x19 DW_FORM_flag_present
90     0, // 0x1a
91     0, // 0x1b
92     0, // 0x1c
93     0, // 0x1d
94     0, // 0x1e
95     0, // 0x1f
96     8, // 0x20 DW_FORM_ref_sig8
97 };
98
99 // Difference with g_form_sizes_addr8:
100 // DW_FORM_strp and DW_FORM_sec_offset are 8 instead of 4
101 static uint8_t
102 g_form_sizes_addr8_dwarf64[] =
103 {
104     0, // 0x00 unused
105     8, // 0x01 DW_FORM_addr
106     0, // 0x02 unused
107     0, // 0x03 DW_FORM_block2
108     0, // 0x04 DW_FORM_block4
109     2, // 0x05 DW_FORM_data2
110     4, // 0x06 DW_FORM_data4
111     8, // 0x07 DW_FORM_data8
112     0, // 0x08 DW_FORM_string
113     0, // 0x09 DW_FORM_block
114     0, // 0x0a DW_FORM_block1
115     1, // 0x0b DW_FORM_data1
116     1, // 0x0c DW_FORM_flag
117     0, // 0x0d DW_FORM_sdata
118     8, // 0x0e DW_FORM_strp
119     0, // 0x0f DW_FORM_udata
120     0, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
121     1, // 0x11 DW_FORM_ref1
122     2, // 0x12 DW_FORM_ref2
123     4, // 0x13 DW_FORM_ref4
124     8, // 0x14 DW_FORM_ref8
125     0, // 0x15 DW_FORM_ref_udata
126     0, // 0x16 DW_FORM_indirect
127     8, // 0x17 DW_FORM_sec_offset
128     0, // 0x18 DW_FORM_exprloc
129     0, // 0x19 DW_FORM_flag_present
130     0, // 0x1a
131     0, // 0x1b
132     0, // 0x1c
133     0, // 0x1d
134     0, // 0x1e
135     0, // 0x1f
136     8, // 0x20 DW_FORM_ref_sig8
137 };
138
139 DWARFFormValue::FixedFormSizes
140 DWARFFormValue::GetFixedFormSizesForAddressSize (uint8_t addr_size, bool is_dwarf64)
141 {
142     if (!is_dwarf64) {
143         switch (addr_size)
144         {
145         case 4: return FixedFormSizes(g_form_sizes_addr4, sizeof(g_form_sizes_addr4));
146         case 8: return FixedFormSizes(g_form_sizes_addr8, sizeof(g_form_sizes_addr8));
147         }
148     } else {
149         if (addr_size == 8)
150             return FixedFormSizes(g_form_sizes_addr8_dwarf64, sizeof(g_form_sizes_addr8_dwarf64));
151         // is_dwarf64 && addr_size == 4 : no provider does this.
152     }
153     return FixedFormSizes();
154 }
155
156 DWARFFormValue::DWARFFormValue() :
157     m_cu (NULL),
158     m_form(0),
159     m_value()
160 {
161 }
162
163 DWARFFormValue::DWARFFormValue(const DWARFCompileUnit* cu, dw_form_t form) :
164     m_cu (cu),
165     m_form(form),
166     m_value()
167 {
168 }
169
170 void
171 DWARFFormValue::Clear()
172 {
173     m_cu = nullptr;
174     m_form = 0;
175     memset(&m_value, 0, sizeof(m_value));
176 }
177
178 bool
179 DWARFFormValue::ExtractValue(const DWARFDataExtractor& data, lldb::offset_t* offset_ptr)
180 {
181     bool indirect = false;
182     bool is_block = false;
183     m_value.data = NULL;
184     uint8_t ref_addr_size;
185     // Read the value for the form into value and follow and DW_FORM_indirect instances we run into
186     do
187     {
188         indirect = false;
189         switch (m_form)
190         {
191         case DW_FORM_addr:      assert(m_cu);
192                                 m_value.value.uval = data.GetMaxU64(offset_ptr, DWARFCompileUnit::GetAddressByteSize(m_cu));  break;
193         case DW_FORM_block2:    m_value.value.uval = data.GetU16(offset_ptr); is_block = true;          break;
194         case DW_FORM_block4:    m_value.value.uval = data.GetU32(offset_ptr); is_block = true;          break;
195         case DW_FORM_data2:     m_value.value.uval = data.GetU16(offset_ptr);                           break;
196         case DW_FORM_data4:     m_value.value.uval = data.GetU32(offset_ptr);                           break;
197         case DW_FORM_data8:     m_value.value.uval = data.GetU64(offset_ptr);                           break;
198         case DW_FORM_string:    m_value.value.cstr = data.GetCStr(offset_ptr);                          break;
199         case DW_FORM_exprloc:
200         case DW_FORM_block:     m_value.value.uval = data.GetULEB128(offset_ptr); is_block = true;      break;
201         case DW_FORM_block1:    m_value.value.uval = data.GetU8(offset_ptr); is_block = true;           break;
202         case DW_FORM_data1:     m_value.value.uval = data.GetU8(offset_ptr);                            break;
203         case DW_FORM_flag:      m_value.value.uval = data.GetU8(offset_ptr);                            break;
204         case DW_FORM_sdata:     m_value.value.sval = data.GetSLEB128(offset_ptr);                       break;
205         case DW_FORM_strp:      assert(m_cu);
206                                 m_value.value.uval = data.GetMaxU64(offset_ptr, DWARFCompileUnit::IsDWARF64(m_cu) ? 8 : 4);  break;
207     //  case DW_FORM_APPLE_db_str:
208         case DW_FORM_udata:     m_value.value.uval = data.GetULEB128(offset_ptr);                       break;
209         case DW_FORM_ref_addr:  assert(m_cu);
210                                 ref_addr_size = 4;
211                                 if (m_cu->GetVersion() <= 2)
212                                     ref_addr_size = m_cu->GetAddressByteSize();
213                                 else
214                                     ref_addr_size = m_cu->IsDWARF64() ? 8 : 4;
215                                 m_value.value.uval = data.GetMaxU64(offset_ptr, ref_addr_size);         break;
216         case DW_FORM_ref1:      m_value.value.uval = data.GetU8(offset_ptr);                            break;
217         case DW_FORM_ref2:      m_value.value.uval = data.GetU16(offset_ptr);                           break;
218         case DW_FORM_ref4:      m_value.value.uval = data.GetU32(offset_ptr);                           break;
219         case DW_FORM_ref8:      m_value.value.uval = data.GetU64(offset_ptr);                           break;
220         case DW_FORM_ref_udata: m_value.value.uval = data.GetULEB128(offset_ptr);                       break;
221         case DW_FORM_indirect:
222             m_form = data.GetULEB128(offset_ptr);
223             indirect = true;
224             break;
225
226         case DW_FORM_sec_offset:     assert(m_cu);
227                                      m_value.value.uval = data.GetMaxU64(offset_ptr, DWARFCompileUnit::IsDWARF64(m_cu) ? 8 : 4); break;
228         case DW_FORM_flag_present:   m_value.value.uval = 1;                                            break;
229         case DW_FORM_ref_sig8:       m_value.value.uval = data.GetU64(offset_ptr);                      break;
230         case DW_FORM_GNU_str_index:  m_value.value.uval = data.GetULEB128(offset_ptr);                  break;
231         case DW_FORM_GNU_addr_index: m_value.value.uval = data.GetULEB128(offset_ptr);                  break;
232         default:
233             return false;
234             break;
235         }
236     } while (indirect);
237
238     if (is_block)
239     {
240         m_value.data = data.PeekData(*offset_ptr, m_value.value.uval);
241         if (m_value.data != NULL)
242         {
243             *offset_ptr += m_value.value.uval;
244         }
245     }
246
247     return true;
248 }
249
250 bool
251 DWARFFormValue::SkipValue(const DWARFDataExtractor& debug_info_data, lldb::offset_t *offset_ptr) const
252 {
253     return DWARFFormValue::SkipValue(m_form, debug_info_data, offset_ptr, m_cu);
254 }
255
256 bool
257 DWARFFormValue::SkipValue(dw_form_t form, const DWARFDataExtractor& debug_info_data, lldb::offset_t *offset_ptr, const DWARFCompileUnit* cu)
258 {
259     uint8_t ref_addr_size;
260     switch (form)
261     {
262     // Blocks if inlined data that have a length field and the data bytes
263     // inlined in the .debug_info
264     case DW_FORM_exprloc:
265     case DW_FORM_block:  { dw_uleb128_t size = debug_info_data.GetULEB128(offset_ptr); *offset_ptr += size; } return true;
266     case DW_FORM_block1: { dw_uleb128_t size = debug_info_data.GetU8(offset_ptr);      *offset_ptr += size; } return true;
267     case DW_FORM_block2: { dw_uleb128_t size = debug_info_data.GetU16(offset_ptr);     *offset_ptr += size; } return true;
268     case DW_FORM_block4: { dw_uleb128_t size = debug_info_data.GetU32(offset_ptr);     *offset_ptr += size; } return true;
269
270     // Inlined NULL terminated C-strings
271     case DW_FORM_string:
272         debug_info_data.GetCStr(offset_ptr);
273         return true;
274
275     // Compile unit address sized values
276     case DW_FORM_addr:
277         *offset_ptr += DWARFCompileUnit::GetAddressByteSize(cu);
278         return true;
279
280     case DW_FORM_ref_addr:
281         ref_addr_size = 4;
282         assert (cu); // CU must be valid for DW_FORM_ref_addr objects or we will get this wrong
283         if (cu->GetVersion() <= 2)
284             ref_addr_size = cu->GetAddressByteSize();
285         else
286             ref_addr_size = cu->IsDWARF64() ? 8 : 4;
287         *offset_ptr += ref_addr_size;
288         return true;
289
290     // 0 bytes values (implied from DW_FORM)
291     case DW_FORM_flag_present:
292         return true;
293
294     // 1 byte values
295     case DW_FORM_data1:
296     case DW_FORM_flag:
297     case DW_FORM_ref1:
298         *offset_ptr += 1;
299         return true;
300
301     // 2 byte values
302     case DW_FORM_data2:
303     case DW_FORM_ref2:
304         *offset_ptr += 2;
305         return true;
306
307     // 32 bit for DWARF 32, 64 for DWARF 64
308     case DW_FORM_sec_offset:
309     case DW_FORM_strp:
310         assert(cu);
311         *offset_ptr += (cu->IsDWARF64() ? 8 : 4);
312         return true;
313
314     // 4 byte values
315     case DW_FORM_data4:
316     case DW_FORM_ref4:
317         *offset_ptr += 4;
318         return true;
319
320     // 8 byte values
321     case DW_FORM_data8:
322     case DW_FORM_ref8:
323     case DW_FORM_ref_sig8:
324         *offset_ptr += 8;
325         return true;
326
327     // signed or unsigned LEB 128 values
328     case DW_FORM_sdata:
329     case DW_FORM_udata:
330     case DW_FORM_ref_udata:
331     case DW_FORM_GNU_addr_index:
332     case DW_FORM_GNU_str_index:
333         debug_info_data.Skip_LEB128(offset_ptr);
334         return true;
335
336     case DW_FORM_indirect:
337         {
338             dw_form_t indirect_form = debug_info_data.GetULEB128(offset_ptr);
339             return DWARFFormValue::SkipValue (indirect_form,
340                                               debug_info_data,
341                                               offset_ptr,
342                                               cu);
343         }
344
345     default:
346         break;
347     }
348     return false;
349 }
350
351
352 void
353 DWARFFormValue::Dump(Stream &s) const
354 {
355     uint64_t uvalue = Unsigned();
356     bool cu_relative_offset = false;
357
358     bool verbose = s.GetVerbose();
359
360     switch (m_form)
361     {
362     case DW_FORM_addr:      s.Address(uvalue, sizeof (uint64_t)); break;
363     case DW_FORM_flag:
364     case DW_FORM_data1:     s.PutHex8(uvalue);         break;
365     case DW_FORM_data2:     s.PutHex16(uvalue);        break;
366     case DW_FORM_sec_offset:
367     case DW_FORM_data4:     s.PutHex32(uvalue);        break;
368     case DW_FORM_ref_sig8:
369     case DW_FORM_data8:     s.PutHex64(uvalue);        break;
370     case DW_FORM_string:    s.QuotedCString(AsCString()); break;
371     case DW_FORM_exprloc:
372     case DW_FORM_block:
373     case DW_FORM_block1:
374     case DW_FORM_block2:
375     case DW_FORM_block4:
376         if (uvalue > 0)
377         {
378             switch (m_form)
379             {
380             case DW_FORM_exprloc:
381             case DW_FORM_block:  s.Printf("<0x%" PRIx64 "> ", uvalue);                break;
382             case DW_FORM_block1: s.Printf("<0x%2.2x> ", (uint8_t)uvalue);      break;
383             case DW_FORM_block2: s.Printf("<0x%4.4x> ", (uint16_t)uvalue);     break;
384             case DW_FORM_block4: s.Printf("<0x%8.8x> ", (uint32_t)uvalue);     break;
385             default:                                                            break;
386             }
387
388             const uint8_t* data_ptr = m_value.data;
389             if (data_ptr)
390             {
391                 const uint8_t* end_data_ptr = data_ptr + uvalue;    // uvalue contains size of block
392                 while (data_ptr < end_data_ptr)
393                 {
394                     s.Printf("%2.2x ", *data_ptr);
395                     ++data_ptr;
396                 }
397             }
398             else
399                 s.PutCString("NULL");
400         }
401         break;
402
403     case DW_FORM_sdata:     s.PutSLEB128(uvalue); break;
404     case DW_FORM_udata:     s.PutULEB128(uvalue); break;
405     case DW_FORM_strp:
406         {
407             const char* dbg_str = AsCString();
408             if (dbg_str)
409             {
410                 if (verbose)
411                     s.Printf(" .debug_str[0x%8.8x] = ", (uint32_t)uvalue);
412                 s.QuotedCString(dbg_str);
413             }
414             else
415             {
416                 s.PutHex32(uvalue);
417             }
418         }
419         break;
420
421     case DW_FORM_ref_addr:
422     {
423         assert (m_cu); // CU must be valid for DW_FORM_ref_addr objects or we will get this wrong
424         if (m_cu->GetVersion() <= 2)
425             s.Address(uvalue, sizeof (uint64_t) * 2);
426         else
427             s.Address(uvalue, 4 * 2);// 4 for DWARF32, 8 for DWARF64, but we don't support DWARF64 yet
428         break;
429     }
430     case DW_FORM_ref1:      cu_relative_offset = true;  if (verbose) s.Printf("cu + 0x%2.2x", (uint8_t)uvalue); break;
431     case DW_FORM_ref2:      cu_relative_offset = true;  if (verbose) s.Printf("cu + 0x%4.4x", (uint16_t)uvalue); break;
432     case DW_FORM_ref4:      cu_relative_offset = true;  if (verbose) s.Printf("cu + 0x%4.4x", (uint32_t)uvalue); break;
433     case DW_FORM_ref8:      cu_relative_offset = true;  if (verbose) s.Printf("cu + 0x%8.8" PRIx64, uvalue); break;
434     case DW_FORM_ref_udata: cu_relative_offset = true;  if (verbose) s.Printf("cu + 0x%" PRIx64, uvalue); break;
435
436     // All DW_FORM_indirect attributes should be resolved prior to calling this function
437     case DW_FORM_indirect:  s.PutCString("DW_FORM_indirect"); break;
438     case DW_FORM_flag_present: break;
439     default:
440         s.Printf("DW_FORM(0x%4.4x)", m_form);
441         break;
442     }
443
444     if (cu_relative_offset)
445     {
446         assert (m_cu); // CU must be valid for DW_FORM_ref forms that are compile unit relative or we will get this wrong
447         if (verbose)
448             s.PutCString(" => ");
449
450         s.Printf("{0x%8.8" PRIx64 "}", uvalue + m_cu->GetOffset());
451     }
452 }
453
454 const char*
455 DWARFFormValue::AsCString() const
456 {
457     SymbolFileDWARF* symbol_file = m_cu->GetSymbolFileDWARF();
458
459     if (m_form == DW_FORM_string)
460     {
461         return m_value.value.cstr;
462     }
463     else if (m_form == DW_FORM_strp)
464     {
465         if (!symbol_file)
466             return nullptr;
467
468         return symbol_file->get_debug_str_data().PeekCStr(m_value.value.uval);
469     }
470     else if (m_form == DW_FORM_GNU_str_index)
471     {
472         if (!symbol_file)
473             return nullptr;
474
475         uint32_t index_size = m_cu->IsDWARF64() ? 8 : 4;
476         lldb::offset_t offset = m_value.value.uval * index_size;
477         dw_offset_t str_offset = symbol_file->get_debug_str_offsets_data().GetMaxU64(&offset, index_size);
478         return symbol_file->get_debug_str_data().PeekCStr(str_offset);
479     }
480     return nullptr;
481 }
482
483 dw_addr_t
484 DWARFFormValue::Address() const
485 {
486     SymbolFileDWARF* symbol_file = m_cu->GetSymbolFileDWARF();
487
488     if (m_form == DW_FORM_addr)
489         return Unsigned();
490
491     assert(m_cu);
492     assert(m_form == DW_FORM_GNU_addr_index);
493
494     if (!symbol_file)
495         return 0;
496
497     uint32_t index_size = m_cu->GetAddressByteSize();
498     dw_offset_t addr_base = m_cu->GetAddrBase();
499     lldb::offset_t offset = addr_base + m_value.value.uval * index_size;
500     return symbol_file->get_debug_addr_data().GetMaxU64(&offset, index_size);
501 }
502
503 uint64_t
504 DWARFFormValue::Reference() const
505 {
506     uint64_t die_offset = m_value.value.uval;
507     switch (m_form)
508     {
509     case DW_FORM_ref1:
510     case DW_FORM_ref2:
511     case DW_FORM_ref4:
512     case DW_FORM_ref8:
513     case DW_FORM_ref_udata:
514         assert (m_cu); // CU must be valid for DW_FORM_ref forms that are compile unit relative or we will get this wrong
515         die_offset += m_cu->GetOffset();
516         break;
517
518     default:
519         break;
520     }
521
522     return die_offset;
523 }
524
525 uint64_t
526 DWARFFormValue::Reference (dw_offset_t base_offset) const
527 {
528     uint64_t die_offset = m_value.value.uval;
529     switch (m_form)
530     {
531         case DW_FORM_ref1:
532         case DW_FORM_ref2:
533         case DW_FORM_ref4:
534         case DW_FORM_ref8:
535         case DW_FORM_ref_udata:
536             die_offset += base_offset;
537             break;
538             
539         default:
540             break;
541     }
542     
543     return die_offset;
544 }
545
546
547 const uint8_t*
548 DWARFFormValue::BlockData() const
549 {
550     return m_value.data;
551 }
552
553
554 bool
555 DWARFFormValue::IsBlockForm(const dw_form_t form)
556 {
557     switch (form)
558     {
559     case DW_FORM_block:
560     case DW_FORM_block1:
561     case DW_FORM_block2:
562     case DW_FORM_block4:
563         return true;
564     }
565     return false;
566 }
567
568 bool
569 DWARFFormValue::IsDataForm(const dw_form_t form)
570 {
571     switch (form)
572     {
573     case DW_FORM_sdata:
574     case DW_FORM_udata:
575     case DW_FORM_data1:
576     case DW_FORM_data2:
577     case DW_FORM_data4:
578     case DW_FORM_data8:
579         return true;
580     }
581     return false;
582 }
583
584 int
585 DWARFFormValue::Compare (const DWARFFormValue& a_value,
586                          const DWARFFormValue& b_value)
587 {
588     dw_form_t a_form = a_value.Form();
589     dw_form_t b_form = b_value.Form();
590     if (a_form < b_form)
591         return -1;
592     if (a_form > b_form)
593         return 1;
594     switch (a_form)
595     {
596     case DW_FORM_addr:
597     case DW_FORM_flag:
598     case DW_FORM_data1:
599     case DW_FORM_data2:
600     case DW_FORM_data4:
601     case DW_FORM_data8:
602     case DW_FORM_udata:
603     case DW_FORM_ref_addr:
604     case DW_FORM_sec_offset:
605     case DW_FORM_flag_present:
606     case DW_FORM_ref_sig8:
607     case DW_FORM_GNU_addr_index:
608         {
609             uint64_t a = a_value.Unsigned();
610             uint64_t b = b_value.Unsigned();
611             if (a < b)
612                 return -1;
613             if (a > b)
614                 return 1;
615             return 0;
616         }
617
618     case DW_FORM_sdata:
619         {
620             int64_t a = a_value.Signed();
621             int64_t b = b_value.Signed();
622             if (a < b)
623                 return -1;
624             if (a > b)
625                 return 1;
626             return 0;
627         }
628
629     case DW_FORM_string:
630     case DW_FORM_strp:
631     case DW_FORM_GNU_str_index:
632         {
633             const char *a_string = a_value.AsCString();
634             const char *b_string = b_value.AsCString();
635             if (a_string == b_string)
636                 return 0;
637             else if (a_string && b_string)
638                 return strcmp(a_string, b_string);
639             else if (a_string == NULL)
640                 return -1;  // A string is NULL, and B is valid
641             else
642                 return 1;   // A string valid, and B is NULL
643         }
644
645
646     case DW_FORM_block:
647     case DW_FORM_block1:
648     case DW_FORM_block2:
649     case DW_FORM_block4:
650     case DW_FORM_exprloc:
651         {
652             uint64_t a_len = a_value.Unsigned();
653             uint64_t b_len = b_value.Unsigned();
654             if (a_len < b_len)
655                 return -1;
656             if (a_len > b_len)
657                 return 1;
658             // The block lengths are the same
659             return memcmp(a_value.BlockData(), b_value.BlockData(), a_value.Unsigned());
660         }
661         break;
662
663     case DW_FORM_ref1:
664     case DW_FORM_ref2:
665     case DW_FORM_ref4:
666     case DW_FORM_ref8:
667     case DW_FORM_ref_udata:
668         {
669             uint64_t a = a_value.Reference();
670             uint64_t b = b_value.Reference();
671             if (a < b)
672                 return -1;
673             if (a > b)
674                 return 1;
675             return 0;
676         }
677
678     case DW_FORM_indirect:
679         assert(!"This shouldn't happen after the form has been extracted...");
680         break;
681
682     default:
683         assert(!"Unhandled DW_FORM");
684         break;
685     }
686     return -1;
687 }
688