]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFDebugLine.cpp
1 //===-- DWARFDebugLine.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 "DWARFDebugLine.h"
11
12 //#define ENABLE_DEBUG_PRINTF   // DO NOT LEAVE THIS DEFINED: DEBUG ONLY!!!
13 #include <assert.h>
14
15 #include "lldb/Core/FileSpecList.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Host/Host.h"
18 #include "lldb/Utility/Log.h"
19 #include "lldb/Utility/Timer.h"
20
21 #include "LogChannelDWARF.h"
22 #include "SymbolFileDWARF.h"
23
24 using namespace lldb;
25 using namespace lldb_private;
26 using namespace std;
27
28 //----------------------------------------------------------------------
29 // Parse
30 //
31 // Parse all information in the debug_line_data into an internal
32 // representation.
33 //----------------------------------------------------------------------
34 void DWARFDebugLine::Parse(const DWARFDataExtractor &debug_line_data) {
35   m_lineTableMap.clear();
36   lldb::offset_t offset = 0;
37   LineTable::shared_ptr line_table_sp(new LineTable);
38   while (debug_line_data.ValidOffset(offset)) {
39     const lldb::offset_t debug_line_offset = offset;
40
41     if (line_table_sp.get() == NULL)
42       break;
43
44     if (ParseStatementTable(debug_line_data, &offset, line_table_sp.get())) {
45       // Make sure we don't don't loop infinitely
46       if (offset <= debug_line_offset)
47         break;
48       // DEBUG_PRINTF("m_lineTableMap[0x%8.8x] = line_table_sp\n",
49       // debug_line_offset);
50       m_lineTableMap[debug_line_offset] = line_table_sp;
51       line_table_sp.reset(new LineTable);
52     } else
53       ++offset; // Try next byte in line table
54   }
55 }
56
57 void DWARFDebugLine::ParseIfNeeded(const DWARFDataExtractor &debug_line_data) {
58   if (m_lineTableMap.empty())
59     Parse(debug_line_data);
60 }
61
62 //----------------------------------------------------------------------
63 // DWARFDebugLine::GetLineTable
64 //----------------------------------------------------------------------
65 DWARFDebugLine::LineTable::shared_ptr
66 DWARFDebugLine::GetLineTable(const dw_offset_t offset) const {
67   DWARFDebugLine::LineTable::shared_ptr line_table_shared_ptr;
68   LineTableConstIter pos = m_lineTableMap.find(offset);
69   if (pos != m_lineTableMap.end())
70     line_table_shared_ptr = pos->second;
71   return line_table_shared_ptr;
72 }
73
74 //----------------------------------------------------------------------
75 // DumpStateToFile
76 //----------------------------------------------------------------------
77 static void DumpStateToFile(dw_offset_t offset,
78                             const DWARFDebugLine::State &state,
79                             void *userData) {
80   Log *log = (Log *)userData;
81   if (state.row == DWARFDebugLine::State::StartParsingLineTable) {
82     // If the row is zero we are being called with the prologue only
83     state.prologue->Dump(log);
84     log->PutCString("Address            Line   Column File");
85     log->PutCString("------------------ ------ ------ ------");
86   } else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) {
87     // Done parsing line table
88   } else {
89     log->Printf("0x%16.16" PRIx64 " %6u %6u %6u%s\n", state.address, state.line,
90                 state.column, state.file, state.end_sequence ? " END" : "");
91   }
92 }
93
94 //----------------------------------------------------------------------
95 // DWARFDebugLine::DumpLineTableRows
96 //----------------------------------------------------------------------
97 bool DWARFDebugLine::DumpLineTableRows(Log *log, SymbolFileDWARF *dwarf2Data,
98                                        dw_offset_t debug_line_offset) {
99   const DWARFDataExtractor &debug_line_data = dwarf2Data->get_debug_line_data();
100
101   if (debug_line_offset == DW_INVALID_OFFSET) {
102     // Dump line table to a single file only
103     debug_line_offset = 0;
104     while (debug_line_data.ValidOffset(debug_line_offset))
105       debug_line_offset =
106           DumpStatementTable(log, debug_line_data, debug_line_offset);
107   } else {
108     // Dump line table to a single file only
109     DumpStatementTable(log, debug_line_data, debug_line_offset);
110   }
111   return false;
112 }
113
114 //----------------------------------------------------------------------
115 // DWARFDebugLine::DumpStatementTable
116 //----------------------------------------------------------------------
117 dw_offset_t
118 DWARFDebugLine::DumpStatementTable(Log *log,
119                                    const DWARFDataExtractor &debug_line_data,
120                                    const dw_offset_t debug_line_offset) {
121   if (debug_line_data.ValidOffset(debug_line_offset)) {
122     lldb::offset_t offset = debug_line_offset;
123     log->Printf("--------------------------------------------------------------"
124                 "--------\n"
125                 "debug_line[0x%8.8x]\n"
126                 "--------------------------------------------------------------"
127                 "--------\n",
128                 debug_line_offset);
129
130     if (ParseStatementTable(debug_line_data, &offset, DumpStateToFile, log))
131       return offset;
132     else
133       return debug_line_offset + 1; // Skip to next byte in .debug_line section
134   }
135
136   return DW_INVALID_OFFSET;
137 }
138
139 //----------------------------------------------------------------------
140 // DumpOpcodes
141 //----------------------------------------------------------------------
142 bool DWARFDebugLine::DumpOpcodes(Log *log, SymbolFileDWARF *dwarf2Data,
143                                  dw_offset_t debug_line_offset,
144                                  uint32_t dump_flags) {
145   const DWARFDataExtractor &debug_line_data = dwarf2Data->get_debug_line_data();
146
147   if (debug_line_data.GetByteSize() == 0) {
148     log->Printf("< EMPTY >\n");
149     return false;
150   }
151
152   if (debug_line_offset == DW_INVALID_OFFSET) {
153     // Dump line table to a single file only
154     debug_line_offset = 0;
155     while (debug_line_data.ValidOffset(debug_line_offset))
156       debug_line_offset = DumpStatementOpcodes(log, debug_line_data,
157                                                debug_line_offset, dump_flags);
158   } else {
159     // Dump line table to a single file only
160     DumpStatementOpcodes(log, debug_line_data, debug_line_offset, dump_flags);
161   }
162   return false;
163 }
164
165 //----------------------------------------------------------------------
166 // DumpStatementOpcodes
167 //----------------------------------------------------------------------
168 dw_offset_t DWARFDebugLine::DumpStatementOpcodes(
169     Log *log, const DWARFDataExtractor &debug_line_data,
170     const dw_offset_t debug_line_offset, uint32_t flags) {
171   lldb::offset_t offset = debug_line_offset;
172   if (debug_line_data.ValidOffset(offset)) {
173     Prologue prologue;
174
175     if (ParsePrologue(debug_line_data, &offset, &prologue)) {
176       log->PutCString("--------------------------------------------------------"
177                       "--------------");
178       log->Printf("debug_line[0x%8.8x]", debug_line_offset);
179       log->PutCString("--------------------------------------------------------"
180                       "--------------\n");
181       prologue.Dump(log);
182     } else {
183       offset = debug_line_offset;
184       log->Printf("0x%8.8" PRIx64 ": skipping pad byte %2.2x", offset,
185                   debug_line_data.GetU8(&offset));
186       return offset;
187     }
188
189     Row row(prologue.default_is_stmt);
190     const dw_offset_t end_offset = debug_line_offset + prologue.total_length +
191                                    sizeof(prologue.total_length);
192
193     assert(debug_line_data.ValidOffset(end_offset - 1));
194
195     while (offset < end_offset) {
196       const uint32_t op_offset = offset;
197       uint8_t opcode = debug_line_data.GetU8(&offset);
198       switch (opcode) {
199       case 0: // Extended Opcodes always start with a zero opcode followed by
200       {       // a uleb128 length so you can skip ones you don't know about
201
202         dw_offset_t ext_offset = offset;
203         dw_uleb128_t len = debug_line_data.GetULEB128(&offset);
204         dw_offset_t arg_size = len - (offset - ext_offset);
205         uint8_t sub_opcode = debug_line_data.GetU8(&offset);
206         //                    if (verbose)
207         //                        log->Printf( "Extended: <%u> %2.2x ", len,
208         //                        sub_opcode);
209
210         switch (sub_opcode) {
211         case DW_LNE_end_sequence:
212           log->Printf("0x%8.8x: DW_LNE_end_sequence", op_offset);
213           row.Dump(log);
214           row.Reset(prologue.default_is_stmt);
215           break;
216
217         case DW_LNE_set_address: {
218           row.address = debug_line_data.GetMaxU64(&offset, arg_size);
219           log->Printf("0x%8.8x: DW_LNE_set_address (0x%" PRIx64 ")", op_offset,
220                       row.address);
221         } break;
222
223         case DW_LNE_define_file: {
224           FileNameEntry fileEntry;
225           fileEntry.name = debug_line_data.GetCStr(&offset);
226           fileEntry.dir_idx = debug_line_data.GetULEB128(&offset);
227           fileEntry.mod_time = debug_line_data.GetULEB128(&offset);
228           fileEntry.length = debug_line_data.GetULEB128(&offset);
229           log->Printf("0x%8.8x: DW_LNE_define_file('%s', dir=%i, "
230                       "mod_time=0x%8.8x, length=%i )",
231                       op_offset, fileEntry.name, fileEntry.dir_idx,
232                       fileEntry.mod_time, fileEntry.length);
233           prologue.file_names.push_back(fileEntry);
234         } break;
235
236         case DW_LNE_set_discriminator: {
237           uint64_t discriminator = debug_line_data.GetULEB128(&offset);
238           log->Printf("0x%8.8x: DW_LNE_set_discriminator (0x%" PRIx64 ")",
239                       op_offset, discriminator);
240         } break;
241         default:
242           log->Printf("0x%8.8x: DW_LNE_??? (%2.2x) - Skipping unknown upcode",
243                       op_offset, opcode);
244           // Length doesn't include the zero opcode byte or the length itself,
245           // but it does include the sub_opcode, so we have to adjust for that
246           // below
247           offset += arg_size;
248           break;
249         }
250       } break;
251
252       // Standard Opcodes
253       case DW_LNS_copy:
254         log->Printf("0x%8.8x: DW_LNS_copy", op_offset);
255         row.Dump(log);
256         break;
257
258       case DW_LNS_advance_pc: {
259         dw_uleb128_t addr_offset_n = debug_line_data.GetULEB128(&offset);
260         dw_uleb128_t addr_offset = addr_offset_n * prologue.min_inst_length;
261         log->Printf("0x%8.8x: DW_LNS_advance_pc (0x%x)", op_offset,
262                     addr_offset);
263         row.address += addr_offset;
264       } break;
265
266       case DW_LNS_advance_line: {
267         dw_sleb128_t line_offset = debug_line_data.GetSLEB128(&offset);
268         log->Printf("0x%8.8x: DW_LNS_advance_line (%i)", op_offset,
269                     line_offset);
270         row.line += line_offset;
271       } break;
272
273       case DW_LNS_set_file:
274         row.file = debug_line_data.GetULEB128(&offset);
275         log->Printf("0x%8.8x: DW_LNS_set_file (%u)", op_offset, row.file);
276         break;
277
278       case DW_LNS_set_column:
279         row.column = debug_line_data.GetULEB128(&offset);
280         log->Printf("0x%8.8x: DW_LNS_set_column (%u)", op_offset, row.column);
281         break;
282
283       case DW_LNS_negate_stmt:
284         row.is_stmt = !row.is_stmt;
285         log->Printf("0x%8.8x: DW_LNS_negate_stmt", op_offset);
286         break;
287
288       case DW_LNS_set_basic_block:
289         row.basic_block = true;
290         log->Printf("0x%8.8x: DW_LNS_set_basic_block", op_offset);
291         break;
292
293       case DW_LNS_const_add_pc: {
294         uint8_t adjust_opcode = 255 - prologue.opcode_base;
295         dw_addr_t addr_offset =
296             (adjust_opcode / prologue.line_range) * prologue.min_inst_length;
297         log->Printf("0x%8.8x: DW_LNS_const_add_pc (0x%8.8" PRIx64 ")",
298                     op_offset, addr_offset);
299         row.address += addr_offset;
300       } break;
301
302       case DW_LNS_fixed_advance_pc: {
303         uint16_t pc_offset = debug_line_data.GetU16(&offset);
304         log->Printf("0x%8.8x: DW_LNS_fixed_advance_pc (0x%4.4x)", op_offset,
305                     pc_offset);
306         row.address += pc_offset;
307       } break;
308
309       case DW_LNS_set_prologue_end:
310         row.prologue_end = true;
311         log->Printf("0x%8.8x: DW_LNS_set_prologue_end", op_offset);
312         break;
313
314       case DW_LNS_set_epilogue_begin:
315         row.epilogue_begin = true;
316         log->Printf("0x%8.8x: DW_LNS_set_epilogue_begin", op_offset);
317         break;
318
319       case DW_LNS_set_isa:
320         row.isa = debug_line_data.GetULEB128(&offset);
321         log->Printf("0x%8.8x: DW_LNS_set_isa (%u)", op_offset, row.isa);
322         break;
323
324       // Special Opcodes
325       default:
326         if (opcode < prologue.opcode_base) {
327           // We have an opcode that this parser doesn't know about, skip the
328           // number of ULEB128 numbers that is says to skip in the prologue's
329           // standard_opcode_lengths array
330           uint8_t n = prologue.standard_opcode_lengths[opcode - 1];
331           log->Printf("0x%8.8x: Special : Unknown skipping %u ULEB128 values.",
332                       op_offset, n);
333           while (n > 0) {
334             debug_line_data.GetULEB128(&offset);
335             --n;
336           }
337         } else {
338           uint8_t adjust_opcode = opcode - prologue.opcode_base;
339           dw_addr_t addr_offset =
340               (adjust_opcode / prologue.line_range) * prologue.min_inst_length;
341           int32_t line_offset =
342               prologue.line_base + (adjust_opcode % prologue.line_range);
343           log->Printf("0x%8.8x: address += 0x%" PRIx64 ",  line += %i\n",
344                       op_offset, (uint64_t)addr_offset, line_offset);
345           row.address += addr_offset;
346           row.line += line_offset;
347           row.Dump(log);
348         }
349         break;
350       }
351     }
352     return end_offset;
353   }
354   return DW_INVALID_OFFSET;
355 }
356
357 //----------------------------------------------------------------------
358 // Parse
359 //
360 // Parse the entire line table contents calling callback each time a new
361 // prologue is parsed and every time a new row is to be added to the line
362 // table.
363 //----------------------------------------------------------------------
364 void DWARFDebugLine::Parse(const DWARFDataExtractor &debug_line_data,
365                            DWARFDebugLine::State::Callback callback,
366                            void *userData) {
367   lldb::offset_t offset = 0;
368   if (debug_line_data.ValidOffset(offset)) {
369     if (!ParseStatementTable(debug_line_data, &offset, callback, userData))
370       ++offset; // Skip to next byte in .debug_line section
371   }
372 }
373
374 //----------------------------------------------------------------------
375 // DWARFDebugLine::ParsePrologue
376 //----------------------------------------------------------------------
377 bool DWARFDebugLine::ParsePrologue(const DWARFDataExtractor &debug_line_data,
378                                    lldb::offset_t *offset_ptr,
379                                    Prologue *prologue) {
380   const lldb::offset_t prologue_offset = *offset_ptr;
381
382   // DEBUG_PRINTF("0x%8.8x: ParsePrologue()\n", *offset_ptr);
383
384   prologue->Clear();
385   uint32_t i;
386   const char *s;
387   prologue->total_length = debug_line_data.GetDWARFInitialLength(offset_ptr);
388   prologue->version = debug_line_data.GetU16(offset_ptr);
389   if (prologue->version < 2 || prologue->version > 4)
390     return false;
391
392   prologue->prologue_length = debug_line_data.GetDWARFOffset(offset_ptr);
393   const lldb::offset_t end_prologue_offset =
394       prologue->prologue_length + *offset_ptr;
395   prologue->min_inst_length = debug_line_data.GetU8(offset_ptr);
396   if (prologue->version >= 4)
397     prologue->maximum_operations_per_instruction =
398         debug_line_data.GetU8(offset_ptr);
399   else
400     prologue->maximum_operations_per_instruction = 1;
401   prologue->default_is_stmt = debug_line_data.GetU8(offset_ptr);
402   prologue->line_base = debug_line_data.GetU8(offset_ptr);
403   prologue->line_range = debug_line_data.GetU8(offset_ptr);
404   prologue->opcode_base = debug_line_data.GetU8(offset_ptr);
405
406   prologue->standard_opcode_lengths.reserve(prologue->opcode_base - 1);
407
408   for (i = 1; i < prologue->opcode_base; ++i) {
409     uint8_t op_len = debug_line_data.GetU8(offset_ptr);
410     prologue->standard_opcode_lengths.push_back(op_len);
411   }
412
413   while (*offset_ptr < end_prologue_offset) {
414     s = debug_line_data.GetCStr(offset_ptr);
415     if (s && s[0])
416       prologue->include_directories.push_back(s);
417     else
418       break;
419   }
420
421   while (*offset_ptr < end_prologue_offset) {
422     const char *name = debug_line_data.GetCStr(offset_ptr);
423     if (name && name[0]) {
424       FileNameEntry fileEntry;
425       fileEntry.name = name;
426       fileEntry.dir_idx = debug_line_data.GetULEB128(offset_ptr);
427       fileEntry.mod_time = debug_line_data.GetULEB128(offset_ptr);
428       fileEntry.length = debug_line_data.GetULEB128(offset_ptr);
429       prologue->file_names.push_back(fileEntry);
430     } else
431       break;
432   }
433
434   // XXX GNU as is broken for 64-Bit DWARF
435   if (*offset_ptr != end_prologue_offset) {
436     Host::SystemLog(Host::eSystemLogWarning,
437                     "warning: parsing line table prologue at 0x%8.8" PRIx64
438                     " should have ended at 0x%8.8" PRIx64
439                     " but it ended at 0x%8.8" PRIx64 "\n",
440                     prologue_offset, end_prologue_offset, *offset_ptr);
441   }
442   return end_prologue_offset;
443 }
444
445 bool DWARFDebugLine::ParseSupportFiles(
446     const lldb::ModuleSP &module_sp, const DWARFDataExtractor &debug_line_data,
447     const lldb_private::FileSpec &cu_comp_dir, dw_offset_t stmt_list,
448     FileSpecList &support_files) {
449   lldb::offset_t offset = stmt_list;
450
451   Prologue prologue;
452   if (!ParsePrologue(debug_line_data, &offset, &prologue)) {
453     Host::SystemLog(Host::eSystemLogError, "error: parsing line table prologue "
454                                            "at 0x%8.8x (parsing ended around "
455                                            "0x%8.8" PRIx64 "\n",
456                     stmt_list, offset);
457     return false;
458   }
459
460   FileSpec file_spec;
461   std::string remapped_file;
462
463   for (uint32_t file_idx = 1;
464        prologue.GetFile(file_idx, cu_comp_dir, file_spec); ++file_idx) {
465     if (module_sp->RemapSourceFile(file_spec.GetPath(), remapped_file))
466       file_spec.SetFile(remapped_file, false, FileSpec::Style::native);
467     support_files.Append(file_spec);
468   }
469   return true;
470 }
471
472 //----------------------------------------------------------------------
473 // ParseStatementTable
474 //
475 // Parse a single line table (prologue and all rows) and call the callback
476 // function once for the prologue (row in state will be zero) and each time a
477 // row is to be added to the line table.
478 //----------------------------------------------------------------------
479 bool DWARFDebugLine::ParseStatementTable(
480     const DWARFDataExtractor &debug_line_data, lldb::offset_t *offset_ptr,
481     DWARFDebugLine::State::Callback callback, void *userData) {
482   Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_LINE));
483   Prologue::shared_ptr prologue(new Prologue());
484
485   const dw_offset_t debug_line_offset = *offset_ptr;
486
487   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
488   Timer scoped_timer(
489       func_cat, "DWARFDebugLine::ParseStatementTable (.debug_line[0x%8.8x])",
490       debug_line_offset);
491
492   if (!ParsePrologue(debug_line_data, offset_ptr, prologue.get())) {
493     if (log)
494       log->Error("failed to parse DWARF line table prologue");
495     // Restore our offset and return false to indicate failure!
496     *offset_ptr = debug_line_offset;
497     return false;
498   }
499
500   if (log)
501     prologue->Dump(log);
502
503   const dw_offset_t end_offset =
504       debug_line_offset + prologue->total_length +
505       (debug_line_data.GetDWARFSizeofInitialLength());
506
507   State state(prologue, log, callback, userData);
508
509   while (*offset_ptr < end_offset) {
510     // DEBUG_PRINTF("0x%8.8x: ", *offset_ptr);
511     uint8_t opcode = debug_line_data.GetU8(offset_ptr);
512
513     if (opcode == 0) {
514       // Extended Opcodes always start with a zero opcode followed by a uleb128
515       // length so you can skip ones you don't know about
516       lldb::offset_t ext_offset = *offset_ptr;
517       dw_uleb128_t len = debug_line_data.GetULEB128(offset_ptr);
518       dw_offset_t arg_size = len - (*offset_ptr - ext_offset);
519
520       // DEBUG_PRINTF("Extended: <%2u> ", len);
521       uint8_t sub_opcode = debug_line_data.GetU8(offset_ptr);
522       switch (sub_opcode) {
523       case DW_LNE_end_sequence:
524         // Set the end_sequence register of the state machine to true and
525         // append a row to the matrix using the current values of the state-
526         // machine registers. Then reset the registers to the initial values
527         // specified above. Every statement program sequence must end with a
528         // DW_LNE_end_sequence instruction which creates a row whose address is
529         // that of the byte after the last target machine instruction of the
530         // sequence.
531         state.end_sequence = true;
532         state.AppendRowToMatrix(*offset_ptr);
533         state.Reset();
534         break;
535
536       case DW_LNE_set_address:
537         // Takes a single relocatable address as an operand. The size of the
538         // operand is the size appropriate to hold an address on the target
539         // machine. Set the address register to the value given by the
540         // relocatable address. All of the other statement program opcodes that
541         // affect the address register add a delta to it. This instruction
542         // stores a relocatable value into it instead.
543         if (arg_size == 4)
544           state.address = debug_line_data.GetU32(offset_ptr);
545         else // arg_size == 8
546           state.address = debug_line_data.GetU64(offset_ptr);
547         break;
548
549       case DW_LNE_define_file:
550         // Takes 4 arguments. The first is a null terminated string containing
551         // a source file name. The second is an unsigned LEB128 number
552         // representing the directory index of the directory in which the file
553         // was found. The third is an unsigned LEB128 number representing the
554         // time of last modification of the file. The fourth is an unsigned
555         // LEB128 number representing the length in bytes of the file. The time
556         // and length fields may contain LEB128(0) if the information is not
557         // available.
558         //
559         // The directory index represents an entry in the include_directories
560         // section of the statement program prologue. The index is LEB128(0) if
561         // the file was found in the current directory of the compilation,
562         // LEB128(1) if it was found in the first directory in the
563         // include_directories section, and so on. The directory index is
564         // ignored for file names that represent full path names.
565         //
566         // The files are numbered, starting at 1, in the order in which they
567         // appear; the names in the prologue come before names defined by the
568         // DW_LNE_define_file instruction. These numbers are used in the file
569         // register of the state machine.
570         {
571           FileNameEntry fileEntry;
572           fileEntry.name = debug_line_data.GetCStr(offset_ptr);
573           fileEntry.dir_idx = debug_line_data.GetULEB128(offset_ptr);
574           fileEntry.mod_time = debug_line_data.GetULEB128(offset_ptr);
575           fileEntry.length = debug_line_data.GetULEB128(offset_ptr);
576           state.prologue->file_names.push_back(fileEntry);
577         }
578         break;
579
580       default:
581         // Length doesn't include the zero opcode byte or the length itself,
582         // but it does include the sub_opcode, so we have to adjust for that
583         // below
584         (*offset_ptr) += arg_size;
585         break;
586       }
587     } else if (opcode < prologue->opcode_base) {
588       switch (opcode) {
589       // Standard Opcodes
590       case DW_LNS_copy:
591         // Takes no arguments. Append a row to the matrix using the current
592         // values of the state-machine registers. Then set the basic_block
593         // register to false.
594         state.AppendRowToMatrix(*offset_ptr);
595         break;
596
597       case DW_LNS_advance_pc:
598         // Takes a single unsigned LEB128 operand, multiplies it by the
599         // min_inst_length field of the prologue, and adds the result to the
600         // address register of the state machine.
601         state.address +=
602             debug_line_data.GetULEB128(offset_ptr) * prologue->min_inst_length;
603         break;
604
605       case DW_LNS_advance_line:
606         // Takes a single signed LEB128 operand and adds that value to the line
607         // register of the state machine.
608         state.line += debug_line_data.GetSLEB128(offset_ptr);
609         break;
610
611       case DW_LNS_set_file:
612         // Takes a single unsigned LEB128 operand and stores it in the file
613         // register of the state machine.
614         state.file = debug_line_data.GetULEB128(offset_ptr);
615         break;
616
617       case DW_LNS_set_column:
618         // Takes a single unsigned LEB128 operand and stores it in the column
619         // register of the state machine.
620         state.column = debug_line_data.GetULEB128(offset_ptr);
621         break;
622
623       case DW_LNS_negate_stmt:
624         // Takes no arguments. Set the is_stmt register of the state machine to
625         // the logical negation of its current value.
626         state.is_stmt = !state.is_stmt;
627         break;
628
629       case DW_LNS_set_basic_block:
630         // Takes no arguments. Set the basic_block register of the state
631         // machine to true
632         state.basic_block = true;
633         break;
634
635       case DW_LNS_const_add_pc:
636         // Takes no arguments. Add to the address register of the state machine
637         // the address increment value corresponding to special opcode 255. The
638         // motivation for DW_LNS_const_add_pc is this: when the statement
639         // program needs to advance the address by a small amount, it can use a
640         // single special opcode, which occupies a single byte. When it needs
641         // to advance the address by up to twice the range of the last special
642         // opcode, it can use DW_LNS_const_add_pc followed by a special opcode,
643         // for a total of two bytes. Only if it needs to advance the address by
644         // more than twice that range will it need to use both
645         // DW_LNS_advance_pc and a special opcode, requiring three or more
646         // bytes.
647         {
648           uint8_t adjust_opcode = 255 - prologue->opcode_base;
649           dw_addr_t addr_offset = (adjust_opcode / prologue->line_range) *
650                                   prologue->min_inst_length;
651           state.address += addr_offset;
652         }
653         break;
654
655       case DW_LNS_fixed_advance_pc:
656         // Takes a single uhalf operand. Add to the address register of the
657         // state machine the value of the (unencoded) operand. This is the only
658         // extended opcode that takes an argument that is not a variable length
659         // number. The motivation for DW_LNS_fixed_advance_pc is this: existing
660         // assemblers cannot emit DW_LNS_advance_pc or special opcodes because
661         // they cannot encode LEB128 numbers or judge when the computation of a
662         // special opcode overflows and requires the use of DW_LNS_advance_pc.
663         // Such assemblers, however, can use DW_LNS_fixed_advance_pc instead,
664         // sacrificing compression.
665         state.address += debug_line_data.GetU16(offset_ptr);
666         break;
667
668       case DW_LNS_set_prologue_end:
669         // Takes no arguments. Set the prologue_end register of the state
670         // machine to true
671         state.prologue_end = true;
672         break;
673
674       case DW_LNS_set_epilogue_begin:
675         // Takes no arguments. Set the basic_block register of the state
676         // machine to true
677         state.epilogue_begin = true;
678         break;
679
680       case DW_LNS_set_isa:
681         // Takes a single unsigned LEB128 operand and stores it in the column
682         // register of the state machine.
683         state.isa = debug_line_data.GetULEB128(offset_ptr);
684         break;
685
686       default:
687         // Handle any unknown standard opcodes here. We know the lengths of
688         // such opcodes because they are specified in the prologue as a
689         // multiple of LEB128 operands for each opcode.
690         {
691           uint8_t i;
692           assert(static_cast<size_t>(opcode - 1) <
693                  prologue->standard_opcode_lengths.size());
694           const uint8_t opcode_length =
695               prologue->standard_opcode_lengths[opcode - 1];
696           for (i = 0; i < opcode_length; ++i)
697             debug_line_data.Skip_LEB128(offset_ptr);
698         }
699         break;
700       }
701     } else {
702       // Special Opcodes
703
704       // A special opcode value is chosen based on the amount that needs
705       // to be added to the line and address registers. The maximum line
706       // increment for a special opcode is the value of the line_base field in
707       // the header, plus the value of the line_range field, minus 1 (line base
708       // + line range - 1). If the desired line increment is greater than the
709       // maximum line increment, a standard opcode must be used instead of a
710       // special opcode. The "address advance" is calculated by dividing the
711       // desired address increment by the minimum_instruction_length field from
712       // the header. The special opcode is then calculated using the following
713       // formula:
714       //
715       //  opcode = (desired line increment - line_base) + (line_range * address
716       //  advance) + opcode_base
717       //
718       // If the resulting opcode is greater than 255, a standard opcode must be
719       // used instead.
720       //
721       // To decode a special opcode, subtract the opcode_base from the opcode
722       // itself to give the adjusted opcode. The amount to increment the
723       // address register is the result of the adjusted opcode divided by the
724       // line_range multiplied by the minimum_instruction_length field from the
725       // header. That is:
726       //
727       //  address increment = (adjusted opcode / line_range) *
728       //  minimum_instruction_length
729       //
730       // The amount to increment the line register is the line_base plus the
731       // result of the adjusted opcode modulo the line_range. That is:
732       //
733       // line increment = line_base + (adjusted opcode % line_range)
734
735       uint8_t adjust_opcode = opcode - prologue->opcode_base;
736       dw_addr_t addr_offset =
737           (adjust_opcode / prologue->line_range) * prologue->min_inst_length;
738       int32_t line_offset =
739           prologue->line_base + (adjust_opcode % prologue->line_range);
740       state.line += line_offset;
741       state.address += addr_offset;
742       state.AppendRowToMatrix(*offset_ptr);
743     }
744   }
745
746   state.Finalize(*offset_ptr);
747
748   return end_offset;
749 }
750
751 //----------------------------------------------------------------------
752 // ParseStatementTableCallback
753 //----------------------------------------------------------------------
754 static void ParseStatementTableCallback(dw_offset_t offset,
755                                         const DWARFDebugLine::State &state,
756                                         void *userData) {
757   DWARFDebugLine::LineTable *line_table = (DWARFDebugLine::LineTable *)userData;
758   if (state.row == DWARFDebugLine::State::StartParsingLineTable) {
759     // Just started parsing the line table, so lets keep a reference to the
760     // prologue using the supplied shared pointer
761     line_table->prologue = state.prologue;
762   } else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) {
763     // Done parsing line table, nothing to do for the cleanup
764   } else {
765     // We have a new row, lets append it
766     line_table->AppendRow(state);
767   }
768 }
769
770 //----------------------------------------------------------------------
771 // ParseStatementTable
772 //
773 // Parse a line table at offset and populate the LineTable class with the
774 // prologue and all rows.
775 //----------------------------------------------------------------------
776 bool DWARFDebugLine::ParseStatementTable(
777     const DWARFDataExtractor &debug_line_data, lldb::offset_t *offset_ptr,
778     LineTable *line_table) {
779   return ParseStatementTable(debug_line_data, offset_ptr,
780                              ParseStatementTableCallback, line_table);
781 }
782
783 inline bool DWARFDebugLine::Prologue::IsValid() const {
784   return SymbolFileDWARF::SupportedVersion(version);
785 }
786
787 //----------------------------------------------------------------------
788 // DWARFDebugLine::Prologue::Dump
789 //----------------------------------------------------------------------
790 void DWARFDebugLine::Prologue::Dump(Log *log) {
791   uint32_t i;
792
793   log->Printf("Line table prologue:");
794   log->Printf("   total_length: 0x%8.8x", total_length);
795   log->Printf("        version: %u", version);
796   log->Printf("prologue_length: 0x%8.8x", prologue_length);
797   log->Printf("min_inst_length: %u", min_inst_length);
798   log->Printf("default_is_stmt: %u", default_is_stmt);
799   log->Printf("      line_base: %i", line_base);
800   log->Printf("     line_range: %u", line_range);
801   log->Printf("    opcode_base: %u", opcode_base);
802
803   for (i = 0; i < standard_opcode_lengths.size(); ++i) {
804     log->Printf("standard_opcode_lengths[%s] = %u", DW_LNS_value_to_name(i + 1),
805                 standard_opcode_lengths[i]);
806   }
807
808   if (!include_directories.empty()) {
809     for (i = 0; i < include_directories.size(); ++i) {
810       log->Printf("include_directories[%3u] = '%s'", i + 1,
811                   include_directories[i]);
812     }
813   }
814
815   if (!file_names.empty()) {
816     log->PutCString("                Dir  Mod Time   File Len   File Name");
817     log->PutCString("                ---- ---------- ---------- "
818                     "---------------------------");
819     for (i = 0; i < file_names.size(); ++i) {
820       const FileNameEntry &fileEntry = file_names[i];
821       log->Printf("file_names[%3u] %4u 0x%8.8x 0x%8.8x %s", i + 1,
822                   fileEntry.dir_idx, fileEntry.mod_time, fileEntry.length,
823                   fileEntry.name);
824     }
825   }
826 }
827
828 //----------------------------------------------------------------------
829 // DWARFDebugLine::ParsePrologue::Append
830 //
831 // Append the contents of the prologue to the binary stream buffer
832 //----------------------------------------------------------------------
833 // void
834 // DWARFDebugLine::Prologue::Append(BinaryStreamBuf& buff) const
835 //{
836 //  uint32_t i;
837 //
838 //  buff.Append32(total_length);
839 //  buff.Append16(version);
840 //  buff.Append32(prologue_length);
841 //  buff.Append8(min_inst_length);
842 //  buff.Append8(default_is_stmt);
843 //  buff.Append8(line_base);
844 //  buff.Append8(line_range);
845 //  buff.Append8(opcode_base);
846 //
847 //  for (i=0; i<standard_opcode_lengths.size(); ++i)
848 //      buff.Append8(standard_opcode_lengths[i]);
849 //
850 //  for (i=0; i<include_directories.size(); ++i)
851 //      buff.AppendCStr(include_directories[i].c_str());
852 //  buff.Append8(0);    // Terminate the include directory section with empty
853 //  string
854 //
855 //  for (i=0; i<file_names.size(); ++i)
856 //  {
857 //      buff.AppendCStr(file_names[i].name.c_str());
858 //      buff.Append32_as_ULEB128(file_names[i].dir_idx);
859 //      buff.Append32_as_ULEB128(file_names[i].mod_time);
860 //      buff.Append32_as_ULEB128(file_names[i].length);
861 //  }
862 //  buff.Append8(0);    // Terminate the file names section with empty string
863 //}
864
865 bool DWARFDebugLine::Prologue::GetFile(uint32_t file_idx,
866     const lldb_private::FileSpec &comp_dir, FileSpec &file) const {
867   uint32_t idx = file_idx - 1; // File indexes are 1 based...
868   if (idx < file_names.size()) {
869     file.SetFile(file_names[idx].name, false, FileSpec::Style::native);
870     if (file.IsRelative()) {
871       if (file_names[idx].dir_idx > 0) {
872         const uint32_t dir_idx = file_names[idx].dir_idx - 1;
873         if (dir_idx < include_directories.size()) {
874           file.PrependPathComponent(include_directories[dir_idx]);
875           if (!file.IsRelative())
876             return true;
877         }
878       }
879
880       if (comp_dir)
881         file.PrependPathComponent(comp_dir);
882     }
883     return true;
884   }
885   return false;
886 }
887
888 //----------------------------------------------------------------------
889 // DWARFDebugLine::LineTable::Dump
890 //----------------------------------------------------------------------
891 void DWARFDebugLine::LineTable::Dump(Log *log) const {
892   if (prologue.get())
893     prologue->Dump(log);
894
895   if (!rows.empty()) {
896     log->PutCString("Address            Line   Column File   ISA Flags");
897     log->PutCString(
898         "------------------ ------ ------ ------ --- -------------");
899     Row::const_iterator pos = rows.begin();
900     Row::const_iterator end = rows.end();
901     while (pos != end) {
902       (*pos).Dump(log);
903       ++pos;
904     }
905   }
906 }
907
908 void DWARFDebugLine::LineTable::AppendRow(const DWARFDebugLine::Row &state) {
909   rows.push_back(state);
910 }
911
912 //----------------------------------------------------------------------
913 // Compare function for the binary search in
914 // DWARFDebugLine::LineTable::LookupAddress()
915 //----------------------------------------------------------------------
916 static bool FindMatchingAddress(const DWARFDebugLine::Row &row1,
917                                 const DWARFDebugLine::Row &row2) {
918   return row1.address < row2.address;
919 }
920
921 //----------------------------------------------------------------------
922 // DWARFDebugLine::LineTable::LookupAddress
923 //----------------------------------------------------------------------
924 uint32_t DWARFDebugLine::LineTable::LookupAddress(dw_addr_t address,
925                                                   dw_addr_t cu_high_pc) const {
926   uint32_t index = UINT32_MAX;
927   if (!rows.empty()) {
928     // Use the lower_bound algorithm to perform a binary search since we know
929     // that our line table data is ordered by address.
930     DWARFDebugLine::Row row;
931     row.address = address;
932     Row::const_iterator begin_pos = rows.begin();
933     Row::const_iterator end_pos = rows.end();
934     Row::const_iterator pos =
935         lower_bound(begin_pos, end_pos, row, FindMatchingAddress);
936     if (pos == end_pos) {
937       if (address < cu_high_pc)
938         return rows.size() - 1;
939     } else {
940       // Rely on fact that we are using a std::vector and we can do pointer
941       // arithmetic to find the row index (which will be one less that what we
942       // found since it will find the first position after the current address)
943       // since std::vector iterators are just pointers to the container type.
944       index = pos - begin_pos;
945       if (pos->address > address) {
946         if (index > 0)
947           --index;
948         else
949           index = UINT32_MAX;
950       }
951     }
952   }
953   return index; // Failed to find address
954 }
955
956 //----------------------------------------------------------------------
957 // DWARFDebugLine::Row::Row
958 //----------------------------------------------------------------------
959 DWARFDebugLine::Row::Row(bool default_is_stmt)
960     : address(0), line(1), column(0), file(1), is_stmt(default_is_stmt),
961       basic_block(false), end_sequence(false), prologue_end(false),
962       epilogue_begin(false), isa(0) {}
963
964 //----------------------------------------------------------------------
965 // Called after a row is appended to the matrix
966 //----------------------------------------------------------------------
967 void DWARFDebugLine::Row::PostAppend() {
968   basic_block = false;
969   prologue_end = false;
970   epilogue_begin = false;
971 }
972
973 //----------------------------------------------------------------------
974 // DWARFDebugLine::Row::Reset
975 //----------------------------------------------------------------------
976 void DWARFDebugLine::Row::Reset(bool default_is_stmt) {
977   address = 0;
978   line = 1;
979   column = 0;
980   file = 1;
981   is_stmt = default_is_stmt;
982   basic_block = false;
983   end_sequence = false;
984   prologue_end = false;
985   epilogue_begin = false;
986   isa = 0;
987 }
988 //----------------------------------------------------------------------
989 // DWARFDebugLine::Row::Dump
990 //----------------------------------------------------------------------
991 void DWARFDebugLine::Row::Dump(Log *log) const {
992   log->Printf("0x%16.16" PRIx64 " %6u %6u %6u %3u %s%s%s%s%s", address, line,
993               column, file, isa, is_stmt ? " is_stmt" : "",
994               basic_block ? " basic_block" : "",
995               prologue_end ? " prologue_end" : "",
996               epilogue_begin ? " epilogue_begin" : "",
997               end_sequence ? " end_sequence" : "");
998 }
999
1000 //----------------------------------------------------------------------
1001 // Compare function LineTable structures
1002 //----------------------------------------------------------------------
1003 static bool AddressLessThan(const DWARFDebugLine::Row &a,
1004                             const DWARFDebugLine::Row &b) {
1005   return a.address < b.address;
1006 }
1007
1008 // Insert a row at the correct address if the addresses can be out of order
1009 // which can only happen when we are linking a line table that may have had
1010 // it's contents rearranged.
1011 void DWARFDebugLine::Row::Insert(Row::collection &state_coll,
1012                                  const Row &state) {
1013   // If we don't have anything yet, or if the address of the last state in our
1014   // line table is less than the current one, just append the current state
1015   if (state_coll.empty() || AddressLessThan(state_coll.back(), state)) {
1016     state_coll.push_back(state);
1017   } else {
1018     // Do a binary search for the correct entry
1019     pair<Row::iterator, Row::iterator> range(equal_range(
1020         state_coll.begin(), state_coll.end(), state, AddressLessThan));
1021
1022     // If the addresses are equal, we can safely replace the previous entry
1023     // with the current one if the one it is replacing is an end_sequence
1024     // entry. We currently always place an extra end sequence when ever we exit
1025     // a valid address range for a function in case the functions get
1026     // rearranged by optimizations or by order specifications. These extra end
1027     // sequences will disappear by getting replaced with valid consecutive
1028     // entries within a compile unit if there are no gaps.
1029     if (range.first == range.second) {
1030       state_coll.insert(range.first, state);
1031     } else {
1032       if ((distance(range.first, range.second) == 1) &&
1033           range.first->end_sequence == true) {
1034         *range.first = state;
1035       } else {
1036         state_coll.insert(range.second, state);
1037       }
1038     }
1039   }
1040 }
1041
1042 void DWARFDebugLine::Row::Dump(Log *log, const Row::collection &state_coll) {
1043   std::for_each(state_coll.begin(), state_coll.end(),
1044                 bind2nd(std::mem_fun_ref(&Row::Dump), log));
1045 }
1046
1047 //----------------------------------------------------------------------
1048 // DWARFDebugLine::State::State
1049 //----------------------------------------------------------------------
1050 DWARFDebugLine::State::State(Prologue::shared_ptr &p, Log *l,
1051                              DWARFDebugLine::State::Callback cb, void *userData)
1052     : Row(p->default_is_stmt), prologue(p), log(l), callback(cb),
1053       callbackUserData(userData), row(StartParsingLineTable) {
1054   // Call the callback with the initial row state of zero for the prologue
1055   if (callback)
1056     callback(0, *this, callbackUserData);
1057 }
1058
1059 //----------------------------------------------------------------------
1060 // DWARFDebugLine::State::Reset
1061 //----------------------------------------------------------------------
1062 void DWARFDebugLine::State::Reset() { Row::Reset(prologue->default_is_stmt); }
1063
1064 //----------------------------------------------------------------------
1065 // DWARFDebugLine::State::AppendRowToMatrix
1066 //----------------------------------------------------------------------
1067 void DWARFDebugLine::State::AppendRowToMatrix(dw_offset_t offset) {
1068   // Each time we are to add an entry into the line table matrix call the
1069   // callback function so that someone can do something with the current state
1070   // of the state machine (like build a line table or dump the line table!)
1071   if (log) {
1072     if (row == 0) {
1073       log->PutCString("Address            Line   Column File   ISA Flags");
1074       log->PutCString(
1075           "------------------ ------ ------ ------ --- -------------");
1076     }
1077     Dump(log);
1078   }
1079
1080   ++row; // Increase the row number before we call our callback for a real row
1081   if (callback)
1082     callback(offset, *this, callbackUserData);
1083   PostAppend();
1084 }
1085
1086 //----------------------------------------------------------------------
1087 // DWARFDebugLine::State::Finalize
1088 //----------------------------------------------------------------------
1089 void DWARFDebugLine::State::Finalize(dw_offset_t offset) {
1090   // Call the callback with a special row state when we are done parsing a line
1091   // table
1092   row = DoneParsingLineTable;
1093   if (callback)
1094     callback(offset, *this, callbackUserData);
1095 }
1096
1097 // void
1098 // DWARFDebugLine::AppendLineTableData
1099 //(
1100 //  const DWARFDebugLine::Prologue* prologue,
1101 //  const DWARFDebugLine::Row::collection& state_coll,
1102 //  const uint32_t addr_size,
1103 //  BinaryStreamBuf &debug_line_data
1104 //)
1105 //{
1106 //  if (state_coll.empty())
1107 //  {
1108 //      // We have no entries, just make an empty line table
1109 //      debug_line_data.Append8(0);
1110 //      debug_line_data.Append8(1);
1111 //      debug_line_data.Append8(DW_LNE_end_sequence);
1112 //  }
1113 //  else
1114 //  {
1115 //      DWARFDebugLine::Row::const_iterator pos;
1116 //      Row::const_iterator end = state_coll.end();
1117 //      bool default_is_stmt = prologue->default_is_stmt;
1118 //      const DWARFDebugLine::Row reset_state(default_is_stmt);
1119 //      const DWARFDebugLine::Row* prev_state = &reset_state;
1120 //      const int32_t max_line_increment_for_special_opcode =
1121 //      prologue->MaxLineIncrementForSpecialOpcode();
1122 //      for (pos = state_coll.begin(); pos != end; ++pos)
1123 //      {
1124 //          const DWARFDebugLine::Row& curr_state = *pos;
1125 //          int32_t line_increment  = 0;
1126 //          dw_addr_t addr_offset   = curr_state.address - prev_state->address;
1127 //          dw_addr_t addr_advance  = (addr_offset) / prologue->min_inst_length;
1128 //          line_increment = (int32_t)(curr_state.line - prev_state->line);
1129 //
1130 //          // If our previous state was the reset state, then let's emit the
1131 //          // address to keep GDB's DWARF parser happy. If we don't start each
1132 //          // sequence with a DW_LNE_set_address opcode, the line table won't
1133 //          // get slid properly in GDB.
1134 //
1135 //          if (prev_state == &reset_state)
1136 //          {
1137 //              debug_line_data.Append8(0); // Extended opcode
1138 //              debug_line_data.Append32_as_ULEB128(addr_size + 1); // Length of
1139 //              opcode bytes
1140 //              debug_line_data.Append8(DW_LNE_set_address);
1141 //              debug_line_data.AppendMax64(curr_state.address, addr_size);
1142 //              addr_advance = 0;
1143 //          }
1144 //
1145 //          if (prev_state->file != curr_state.file)
1146 //          {
1147 //              debug_line_data.Append8(DW_LNS_set_file);
1148 //              debug_line_data.Append32_as_ULEB128(curr_state.file);
1149 //          }
1150 //
1151 //          if (prev_state->column != curr_state.column)
1152 //          {
1153 //              debug_line_data.Append8(DW_LNS_set_column);
1154 //              debug_line_data.Append32_as_ULEB128(curr_state.column);
1155 //          }
1156 //
1157 //          // Don't do anything fancy if we are at the end of a sequence
1158 //          // as we don't want to push any extra rows since the
1159 //          DW_LNE_end_sequence
1160 //          // will push a row itself!
1161 //          if (curr_state.end_sequence)
1162 //          {
1163 //              if (line_increment != 0)
1164 //              {
1165 //                  debug_line_data.Append8(DW_LNS_advance_line);
1166 //                  debug_line_data.Append32_as_SLEB128(line_increment);
1167 //              }
1168 //
1169 //              if (addr_advance > 0)
1170 //              {
1171 //                  debug_line_data.Append8(DW_LNS_advance_pc);
1172 //                  debug_line_data.Append32_as_ULEB128(addr_advance);
1173 //              }
1174 //
1175 //              // Now push the end sequence on!
1176 //              debug_line_data.Append8(0);
1177 //              debug_line_data.Append8(1);
1178 //              debug_line_data.Append8(DW_LNE_end_sequence);
1179 //
1180 //              prev_state = &reset_state;
1181 //          }
1182 //          else
1183 //          {
1184 //              if (line_increment || addr_advance)
1185 //              {
1186 //                  if (line_increment > max_line_increment_for_special_opcode)
1187 //                  {
1188 //                      debug_line_data.Append8(DW_LNS_advance_line);
1189 //                      debug_line_data.Append32_as_SLEB128(line_increment);
1190 //                      line_increment = 0;
1191 //                  }
1192 //
1193 //                  uint32_t special_opcode = (line_increment >=
1194 //                  prologue->line_base) ? ((line_increment -
1195 //                  prologue->line_base) + (prologue->line_range * addr_advance)
1196 //                  + prologue->opcode_base) : 256;
1197 //                  if (special_opcode > 255)
1198 //                  {
1199 //                      // Both the address and line won't fit in one special
1200 //                      opcode
1201 //                      // check to see if just the line advance will?
1202 //                      uint32_t special_opcode_line = ((line_increment >=
1203 //                      prologue->line_base) && (line_increment != 0)) ?
1204 //                              ((line_increment - prologue->line_base) +
1205 //                              prologue->opcode_base) : 256;
1206 //
1207 //
1208 //                      if (special_opcode_line > 255)
1209 //                      {
1210 //                          // Nope, the line advance won't fit by itself, check
1211 //                          the address increment by itself
1212 //                          uint32_t special_opcode_addr = addr_advance ?
1213 //                              ((0 - prologue->line_base) +
1214 //                              (prologue->line_range * addr_advance) +
1215 //                              prologue->opcode_base) : 256;
1216 //
1217 //                          if (special_opcode_addr > 255)
1218 //                          {
1219 //                              // Neither the address nor the line will fit in
1220 //                              a
1221 //                              // special opcode, we must manually enter both
1222 //                              then
1223 //                              // do a DW_LNS_copy to push a row (special
1224 //                              opcode
1225 //                              // automatically imply a new row is pushed)
1226 //                              if (line_increment != 0)
1227 //                              {
1228 //                                  debug_line_data.Append8(DW_LNS_advance_line);
1229 //                                  debug_line_data.Append32_as_SLEB128(line_increment);
1230 //                              }
1231 //
1232 //                              if (addr_advance > 0)
1233 //                              {
1234 //                                  debug_line_data.Append8(DW_LNS_advance_pc);
1235 //                                  debug_line_data.Append32_as_ULEB128(addr_advance);
1236 //                              }
1237 //
1238 //                              // Now push a row onto the line table manually
1239 //                              debug_line_data.Append8(DW_LNS_copy);
1240 //
1241 //                          }
1242 //                          else
1243 //                          {
1244 //                              // The address increment alone will fit into a
1245 //                              special opcode
1246 //                              // so modify our line change, then issue a
1247 //                              special opcode
1248 //                              // for the address increment and it will push a
1249 //                              row into the
1250 //                              // line table
1251 //                              if (line_increment != 0)
1252 //                              {
1253 //                                  debug_line_data.Append8(DW_LNS_advance_line);
1254 //                                  debug_line_data.Append32_as_SLEB128(line_increment);
1255 //                              }
1256 //
1257 //                              // Advance of line and address will fit into a
1258 //                              single byte special opcode
1259 //                              // and this will also push a row onto the line
1260 //                              table
1261 //                              debug_line_data.Append8(special_opcode_addr);
1262 //                          }
1263 //                      }
1264 //                      else
1265 //                      {
1266 //                          // The line change alone will fit into a special
1267 //                          opcode
1268 //                          // so modify our address increment first, then issue
1269 //                          a
1270 //                          // special opcode for the line change and it will
1271 //                          push
1272 //                          // a row into the line table
1273 //                          if (addr_advance > 0)
1274 //                          {
1275 //                              debug_line_data.Append8(DW_LNS_advance_pc);
1276 //                              debug_line_data.Append32_as_ULEB128(addr_advance);
1277 //                          }
1278 //
1279 //                          // Advance of line and address will fit into a
1280 //                          single byte special opcode
1281 //                          // and this will also push a row onto the line table
1282 //                          debug_line_data.Append8(special_opcode_line);
1283 //                      }
1284 //                  }
1285 //                  else
1286 //                  {
1287 //                      // Advance of line and address will fit into a single
1288 //                      byte special opcode
1289 //                      // and this will also push a row onto the line table
1290 //                      debug_line_data.Append8(special_opcode);
1291 //                  }
1292 //              }
1293 //              prev_state = &curr_state;
1294 //          }
1295 //      }
1296 //  }
1297 //}