1919#include " llvm/Support/Compiler.h"
2020#include " llvm/Support/DataExtractor.h"
2121#include " llvm/Support/Errc.h"
22+ #include " llvm/Support/Error.h"
2223#include " llvm/Support/ErrorHandling.h"
2324#include " llvm/Support/Format.h"
2425#include " llvm/Support/raw_ostream.h"
@@ -204,7 +205,7 @@ raw_ostream &llvm::dwarf::operator<<(raw_ostream &OS, const UnwindTable &Rows) {
204205 return OS;
205206}
206207
207- Expected<UnwindTable> UnwindTable::create (const FDE *Fde) {
208+ Expected<UnwindTable> llvm::dwarf::createUnwindTable (const FDE *Fde) {
208209 const CIE *Cie = Fde->getLinkedCIE ();
209210 if (Cie == nullptr )
210211 return createStringError (errc::invalid_argument,
@@ -213,46 +214,56 @@ Expected<UnwindTable> UnwindTable::create(const FDE *Fde) {
213214
214215 // Rows will be empty if there are no CFI instructions.
215216 if (Cie->cfis ().empty () && Fde->cfis ().empty ())
216- return UnwindTable ();
217+ return UnwindTable ({} );
217218
218- UnwindTable UT ;
219+ UnwindTable::RowContainer CieRows ;
219220 UnwindRow Row;
220221 Row.setAddress (Fde->getInitialLocation ());
221- UT.EndAddress = Fde->getInitialLocation () + Fde->getAddressRange ();
222- if (Error CieError = UT.parseRows (Cie->cfis (), Row, nullptr ))
222+ if (Error CieError = parseRows (Cie->cfis (), Row, nullptr ).moveInto (CieRows))
223223 return std::move (CieError);
224224 // We need to save the initial locations of registers from the CIE parsing
225225 // in case we run into DW_CFA_restore or DW_CFA_restore_extended opcodes.
226+ UnwindTable::RowContainer FdeRows;
226227 const RegisterLocations InitialLocs = Row.getRegisterLocations ();
227- if (Error FdeError = UT.parseRows (Fde->cfis (), Row, &InitialLocs))
228+ if (Error FdeError =
229+ parseRows (Fde->cfis (), Row, &InitialLocs).moveInto (FdeRows))
228230 return std::move (FdeError);
231+
232+ UnwindTable::RowContainer AllRows;
233+ AllRows.insert (AllRows.end (), CieRows.begin (), CieRows.end ());
234+ AllRows.insert (AllRows.end (), FdeRows.begin (), FdeRows.end ());
235+
229236 // May be all the CFI instructions were DW_CFA_nop amd Row becomes empty.
230237 // Do not add that to the unwind table.
231238 if (Row.getRegisterLocations ().hasLocations () ||
232239 Row.getCFAValue ().getLocation () != UnwindLocation::Unspecified)
233- UT. Rows .push_back (Row);
234- return UT ;
240+ AllRows .push_back (Row);
241+ return UnwindTable ( std::move (AllRows)) ;
235242}
236243
237- Expected<UnwindTable> UnwindTable::create (const CIE *Cie) {
244+ Expected<UnwindTable> llvm::dwarf::createUnwindTable (const CIE *Cie) {
238245 // Rows will be empty if there are no CFI instructions.
239246 if (Cie->cfis ().empty ())
240- return UnwindTable ();
247+ return UnwindTable ({} );
241248
242- UnwindTable UT ;
249+ UnwindTable::RowContainer Rows ;
243250 UnwindRow Row;
244- if (Error CieError = UT. parseRows (Cie->cfis (), Row, nullptr ))
251+ if (Error CieError = parseRows (Cie->cfis (), Row, nullptr ). moveInto (Rows ))
245252 return std::move (CieError);
246253 // May be all the CFI instructions were DW_CFA_nop amd Row becomes empty.
247254 // Do not add that to the unwind table.
248255 if (Row.getRegisterLocations ().hasLocations () ||
249256 Row.getCFAValue ().getLocation () != UnwindLocation::Unspecified)
250- UT. Rows .push_back (Row);
251- return UT ;
257+ Rows.push_back (Row);
258+ return UnwindTable ( std::move (Rows)) ;
252259}
253260
254- Error UnwindTable::parseRows (const CFIProgram &CFIP, UnwindRow &Row,
255- const RegisterLocations *InitialLocs) {
261+ Expected<UnwindTable::RowContainer>
262+ llvm::dwarf::parseRows (const CFIProgram &CFIP, UnwindRow &Row,
263+ const RegisterLocations *InitialLocs) {
264+ // All the unwinding rows parsed during processing of the CFI program.
265+ UnwindTable::RowContainer Rows;
266+
256267 // State consists of CFA value and register locations.
257268 std::vector<std::pair<UnwindLocation, RegisterLocations>> States;
258269 for (const CFIProgram::Instruction &Inst : CFIP) {
@@ -554,7 +565,7 @@ Error UnwindTable::parseRows(const CFIProgram &CFIP, UnwindRow &Row,
554565 break ;
555566 }
556567 }
557- return Error::success () ;
568+ return Rows ;
558569}
559570
560571// Returns the CIE identifier to be used by the requested format.
@@ -607,7 +618,7 @@ void CIE::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
607618 /* InitialLocation=*/ {});
608619 OS << " \n " ;
609620
610- if (Expected<UnwindTable> RowsOrErr = UnwindTable::create (this ))
621+ if (Expected<UnwindTable> RowsOrErr = createUnwindTable (this ))
611622 RowsOrErr->dump (OS, DumpOpts, 1 );
612623 else {
613624 DumpOpts.RecoverableErrorHandler (joinErrors (
@@ -635,7 +646,7 @@ void FDE::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
635646 printCFIProgram (CFIs, OS, DumpOpts, /* IndentLevel=*/ 1 , InitialLocation);
636647 OS << " \n " ;
637648
638- if (Expected<UnwindTable> RowsOrErr = UnwindTable::create (this ))
649+ if (Expected<UnwindTable> RowsOrErr = createUnwindTable (this ))
639650 RowsOrErr->dump (OS, DumpOpts, 1 );
640651 else {
641652 DumpOpts.RecoverableErrorHandler (joinErrors (
0 commit comments