diff options
| author | Mathieu Chartier <mathieuc@google.com> | 2018-09-12 21:52:18 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-09-12 21:52:18 +0000 |
| commit | 7dca45b9677c16a54347cdc0d08bfa2bdd94b464 (patch) | |
| tree | 5d2f204df80837c7a2dedfefe573057d5b1587ad /libdexfile | |
| parent | c409d4659e745fc6adb78b866c2664a1eefb7db4 (diff) | |
| parent | 3e2e123239952c80e1b37431bf2efbbe07a41940 (diff) | |
| download | art-7dca45b9677c16a54347cdc0d08bfa2bdd94b464.tar.gz art-7dca45b9677c16a54347cdc0d08bfa2bdd94b464.tar.bz2 art-7dca45b9677c16a54347cdc0d08bfa2bdd94b464.zip | |
Merge "Refactor debug info position visiting"
Diffstat (limited to 'libdexfile')
| -rw-r--r-- | libdexfile/dex/code_item_accessors-inl.h | 30 | ||||
| -rw-r--r-- | libdexfile/dex/code_item_accessors.h | 10 | ||||
| -rw-r--r-- | libdexfile/dex/dex_file-inl.h | 40 | ||||
| -rw-r--r-- | libdexfile/dex/dex_file.cc | 16 | ||||
| -rw-r--r-- | libdexfile/dex/dex_file.h | 26 |
5 files changed, 65 insertions, 57 deletions
diff --git a/libdexfile/dex/code_item_accessors-inl.h b/libdexfile/dex/code_item_accessors-inl.h index c166f5f19e..c7e876e16a 100644 --- a/libdexfile/dex/code_item_accessors-inl.h +++ b/libdexfile/dex/code_item_accessors-inl.h @@ -199,6 +199,36 @@ inline bool CodeItemDebugInfoAccessor::DecodeDebugLocalInfo(bool is_static, context); } +template <typename Visitor> +inline uint32_t CodeItemDebugInfoAccessor::VisitParameterNames(const Visitor& visitor) const { + const uint8_t* stream = dex_file_->GetDebugInfoStream(DebugInfoOffset()); + return (stream != nullptr) ? DexFile::DecodeDebugInfoParameterNames(&stream, visitor) : 0u; +} + +inline bool CodeItemDebugInfoAccessor::GetLineNumForPc(const uint32_t address, + uint32_t* line_num) const { + return DecodeDebugPositionInfo([&](const DexFile::PositionInfo& entry) { + // We know that this callback will be called in ascending address order, so keep going until we + // find a match or we've just gone past it. + if (entry.address_ > address) { + // The line number from the previous positions callback will be the final result. + return true; + } + *line_num = entry.line_; + return entry.address_ == address; + }); +} + +template <typename Visitor> +inline bool CodeItemDebugInfoAccessor::DecodeDebugPositionInfo(const Visitor& visitor) const { + return dex_file_->DecodeDebugPositionInfo( + dex_file_->GetDebugInfoStream(DebugInfoOffset()), + [this](uint32_t idx) { + return dex_file_->StringDataByIdx(dex::StringIndex(idx)); + }, + visitor); +} + } // namespace art #endif // ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_INL_H_ diff --git a/libdexfile/dex/code_item_accessors.h b/libdexfile/dex/code_item_accessors.h index 695cc7b1b2..c2aa23c17d 100644 --- a/libdexfile/dex/code_item_accessors.h +++ b/libdexfile/dex/code_item_accessors.h @@ -157,6 +157,16 @@ class CodeItemDebugInfoAccessor : public CodeItemDataAccessor { NewLocalCallback new_local, void* context) const; + // Visit each parameter in the debug information. Returns the line number. + // The argument of the Visitor is dex::StringIndex. + template <typename Visitor> + uint32_t VisitParameterNames(const Visitor& visitor) const; + + template <typename Visitor> + bool DecodeDebugPositionInfo(const Visitor& visitor) const; + + bool GetLineNumForPc(const uint32_t pc, uint32_t* line_num) const; + protected: ALWAYS_INLINE void Init(const CompactDexFile::CodeItem& code_item, uint32_t dex_method_index); ALWAYS_INLINE void Init(const StandardDexFile::CodeItem& code_item); diff --git a/libdexfile/dex/dex_file-inl.h b/libdexfile/dex/dex_file-inl.h index c512361586..eca9ee945b 100644 --- a/libdexfile/dex/dex_file-inl.h +++ b/libdexfile/dex/dex_file-inl.h @@ -22,6 +22,7 @@ #include "base/casts.h" #include "base/leb128.h" #include "base/stringpiece.h" +#include "base/utils.h" #include "class_iterator.h" #include "compact_dex_file.h" #include "dex_instruction_iterator.h" @@ -401,19 +402,14 @@ bool DexFile::DecodeDebugLocalInfo(uint32_t registers_size, template<typename DexDebugNewPosition, typename IndexToStringData> bool DexFile::DecodeDebugPositionInfo(const uint8_t* stream, - IndexToStringData index_to_string_data, - DexDebugNewPosition position_functor, - void* context) { + const IndexToStringData& index_to_string_data, + const DexDebugNewPosition& position_functor) { if (stream == nullptr) { return false; } - PositionInfo entry = PositionInfo(); - entry.line_ = DecodeUnsignedLeb128(&stream); - uint32_t parameters_size = DecodeUnsignedLeb128(&stream); - for (uint32_t i = 0; i < parameters_size; ++i) { - DecodeUnsignedLeb128P1(&stream); // Parameter name. - } + PositionInfo entry; + entry.line_ = DecodeDebugInfoParameterNames(&stream, VoidFunctor()); for (;;) { uint8_t opcode = *stream++; @@ -456,7 +452,7 @@ bool DexFile::DecodeDebugPositionInfo(const uint8_t* stream, int adjopcode = opcode - DBG_FIRST_SPECIAL; entry.address_ += adjopcode / DBG_LINE_RANGE; entry.line_ += DBG_LINE_BASE + (adjopcode % DBG_LINE_RANGE); - if (position_functor(context, entry)) { + if (position_functor(entry)) { return true; // early exit. } entry.prologue_end_ = false; @@ -467,18 +463,6 @@ bool DexFile::DecodeDebugPositionInfo(const uint8_t* stream, } } -template<typename DexDebugNewPosition> -bool DexFile::DecodeDebugPositionInfo(uint32_t debug_info_offset, - DexDebugNewPosition position_functor, - void* context) const { - return DecodeDebugPositionInfo(GetDebugInfoStream(debug_info_offset), - [this](uint32_t idx) { - return StringDataByIdx(dex::StringIndex(idx)); - }, - position_functor, - context); -} - inline const CompactDexFile* DexFile::AsCompactDexFile() const { DCHECK(IsCompactDexFile()); return down_cast<const CompactDexFile*>(this); @@ -502,6 +486,18 @@ inline IterationRange<ClassIterator> DexFile::GetClasses() const { return { ClassIterator(*this, 0u), ClassIterator(*this, NumClassDefs()) }; } +// Returns the line number +template <typename Visitor> +inline uint32_t DexFile::DecodeDebugInfoParameterNames(const uint8_t** debug_info, + const Visitor& visitor) { + uint32_t line = DecodeUnsignedLeb128(debug_info); + const uint32_t parameters_size = DecodeUnsignedLeb128(debug_info); + for (uint32_t i = 0; i < parameters_size; ++i) { + visitor(dex::StringIndex(DecodeUnsignedLeb128P1(debug_info))); + } + return line; +} + } // namespace art #endif // ART_LIBDEXFILE_DEX_DEX_FILE_INL_H_ diff --git a/libdexfile/dex/dex_file.cc b/libdexfile/dex/dex_file.cc index a3e62216b0..48f38ca8a1 100644 --- a/libdexfile/dex/dex_file.cc +++ b/libdexfile/dex/dex_file.cc @@ -492,22 +492,6 @@ int32_t DexFile::FindTryItem(const TryItem* try_items, uint32_t tries_size, uint return -1; } -bool DexFile::LineNumForPcCb(void* raw_context, const PositionInfo& entry) { - LineNumFromPcContext* context = reinterpret_cast<LineNumFromPcContext*>(raw_context); - - // We know that this callback will be called in - // ascending address order, so keep going until we find - // a match or we've just gone past it. - if (entry.address_ > context->address_) { - // The line number from the previous positions callback - // wil be the final result. - return true; - } else { - context->line_num_ = entry.line_; - return entry.address_ == context->address_; - } -} - // Read a signed integer. "zwidth" is the zero-based byte count. int32_t DexFile::ReadSignedInt(const uint8_t* ptr, int zwidth) { int32_t val = 0; diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h index fc218fba71..3e4a4811c3 100644 --- a/libdexfile/dex/dex_file.h +++ b/libdexfile/dex/dex_file.h @@ -782,8 +782,6 @@ class DexFile { // Callback for "new locals table entry". typedef void (*DexDebugNewLocalCb)(void* context, const LocalInfo& entry); - static bool LineNumForPcCb(void* context, const PositionInfo& entry); - const AnnotationsDirectoryItem* GetAnnotationsDirectory(const ClassDef& class_def) const { return DataPointer<AnnotationsDirectoryItem>(class_def.annotations_off_); } @@ -865,15 +863,6 @@ class DexFile { DBG_LINE_RANGE = 15, }; - struct LineNumFromPcContext { - LineNumFromPcContext(uint32_t address, uint32_t line_num) - : address_(address), line_num_(line_num) {} - uint32_t address_; - uint32_t line_num_; - private: - DISALLOW_COPY_AND_ASSIGN(LineNumFromPcContext); - }; - // Returns false if there is no debugging information or if it cannot be decoded. template<typename NewLocalCallback, typename IndexToStringData, typename TypeIndexToStringData> static bool DecodeDebugLocalInfo(const uint8_t* stream, @@ -902,13 +891,8 @@ class DexFile { // Returns false if there is no debugging information or if it cannot be decoded. template<typename DexDebugNewPosition, typename IndexToStringData> static bool DecodeDebugPositionInfo(const uint8_t* stream, - IndexToStringData index_to_string_data, - DexDebugNewPosition position_functor, - void* context); - template<typename DexDebugNewPosition> - bool DecodeDebugPositionInfo(uint32_t debug_info_offset, - DexDebugNewPosition position_functor, - void* context) const; + const IndexToStringData& index_to_string_data, + const DexDebugNewPosition& position_functor); const char* GetSourceFile(const ClassDef& class_def) const { if (!class_def.source_file_idx_.IsValid()) { @@ -1016,7 +1000,11 @@ class DexFile { // Iterate dex classes and remove hiddenapi flags in fields and methods. void UnhideApis() const; - inline IterationRange<ClassIterator> GetClasses() const; + IterationRange<ClassIterator> GetClasses() const; + + template <typename Visitor> + static uint32_t DecodeDebugInfoParameterNames(const uint8_t** debug_info, + const Visitor& visitor); protected: // First Dex format version supporting default methods. |
