Home | History | Annotate | Download | only in libunwindstack
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _LIBUNWINDSTACK_DEX_FILE_H
     18 #define _LIBUNWINDSTACK_DEX_FILE_H
     19 
     20 #include <stdint.h>
     21 
     22 #include <memory>
     23 #include <string>
     24 #include <vector>
     25 
     26 #include <dex/dex_file-inl.h>
     27 
     28 namespace unwindstack {
     29 
     30 class DexFile {
     31  public:
     32   DexFile() = default;
     33   virtual ~DexFile() = default;
     34 
     35   bool GetMethodInformation(uint64_t dex_offset, std::string* method_name, uint64_t* method_offset);
     36 
     37   static DexFile* Create(uint64_t dex_file_offset_in_memory, Memory* memory, MapInfo* info);
     38 
     39  protected:
     40   std::unique_ptr<const art::DexFile> dex_file_;
     41 };
     42 
     43 class DexFileFromFile : public DexFile {
     44  public:
     45   DexFileFromFile() = default;
     46   virtual ~DexFileFromFile();
     47 
     48   bool Open(uint64_t dex_file_offset_in_file, const std::string& name);
     49 
     50  private:
     51   void* mapped_memory_ = nullptr;
     52   size_t size_ = 0;
     53 };
     54 
     55 class DexFileFromMemory : public DexFile {
     56  public:
     57   DexFileFromMemory() = default;
     58   virtual ~DexFileFromMemory() = default;
     59 
     60   bool Open(uint64_t dex_file_offset_in_memory, Memory* memory);
     61 
     62  private:
     63   std::vector<uint8_t> memory_;
     64 };
     65 
     66 }  // namespace unwindstack
     67 
     68 #endif  // _LIBUNWINDSTACK_DEX_FILE_H
     69