library: added dp_*{h,cc} files as libbarrydp library ('.debug' parser)
[barry.git] / src / dp_codinfo.h
blob41b4614a5bf699d9a2349e61eae458a0afcc4388
1 ///
2 /// \file dp_codinfo.h
3 /// Debug file parsing
4 ///
6 /*
7 Copyright (C) 2009, Nicolas VIVIEN
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRYJDG_CODINFO_H__
23 #define __BARRYJDG_CODINFO_H__
26 #include <iosfwd>
27 #include <string>
28 #include <vector>
31 #define COD_DEBUG_APPNAME_HEADERFIELD 0x0
32 #define COD_DEBUG_UNIQUEID_HEADERFIELD 0x8
34 #define COD_DEBUG_NONE_FIELD 0x0
35 #define COD_DEBUG_BOOLEAN_FIELD 0x1
36 #define COD_DEBUG_BYTE_FIELD 0x2
37 #define COD_DEBUG_CHAR_FIELD 0x3
38 #define COD_DEBUG_SHORT_FIELD 0x4
39 #define COD_DEBUG_INT_FIELD 0x5
40 #define COD_DEBUG_LONG_FIELD 0x6
41 #define COD_DEBUG_CLASS_FIELD 0x7
42 #define COD_DEBUG_ARRAY_FIELD 0x8
43 #define COD_DEBUG_VOID_FIELD 0xA
44 #define COD_DEBUG_DOUBLE_FIELD 0xC
47 namespace Barry {
49 namespace JDG {
52 class JDGDebugFileList;
53 class JDGDebugFileEntry;
54 class JDGClassList;
55 class JDGClassEntry;
58 class JDGDebugFileList : public std::vector<JDGDebugFileEntry> {
59 public:
60 void AddElement(uint32_t uniqueid, std::string appname, std::string filename);
61 void Dump(std::ostream &os) const;
63 inline std::ostream& operator<<(std::ostream &os, const JDGDebugFileList &list) {
64 list.Dump(os);
65 return os;
69 class JDGDebugFileEntry {
70 protected:
72 public:
73 std::string fileName;
74 std::string appName;
75 uint32_t uniqueId;
77 void Dump(std::ostream &os) const;
79 private:
83 class JDGClassList : public std::vector<JDGClassEntry> {
84 protected:
86 public:
87 void createDefaultEntries();
89 private:
93 class JDGClassEntry {
94 protected:
96 public:
97 // For JDB
98 int index;
100 // Read from the ".debug" file
101 std::string className;
102 std::string classPath;
103 std::string sourceFile;
105 uint32_t type;
106 uint32_t unknown02;
107 uint32_t unknown03;
108 uint32_t id;
109 uint32_t unknown05;
110 uint32_t unknown06;
111 uint32_t unknown07;
112 uint32_t unknown08;
114 std::string getFullClassName() { return classPath + "." + className; };
116 private:
122 class JDGCodInfo {
123 protected:
125 public:
126 uint32_t uniqueId;
127 std::string appName;
128 JDGClassList classList;
130 bool loadDebugFile(const char *filename);
132 void parseHeaderSection(std::ifstream &input);
133 void parseTypeSection(std::ifstream &input);
135 uint32_t getUniqueId();
136 std::string getAppName();
138 private:
139 uint32_t parseNextHeaderField(std::ifstream &input);
140 uint32_t parseNextTypeField(std::ifstream &input);
142 void parseAppName(std::ifstream &input);
143 void parseUniqueId(std::ifstream &input);
145 void parseBoolean(std::ifstream &input);
146 void parseByte(std::ifstream &input);
147 void parseChar(std::ifstream &input);
148 void parseShort(std::ifstream &input);
149 void parseInt(std::ifstream &input);
150 void parseLong(std::ifstream &input);
151 void parseClass(std::ifstream &input);
152 void parseArray(std::ifstream &input);
153 void parseVoid(std::ifstream &input);
154 void parseDouble(std::ifstream &input);
158 void searchDebugFile(JDGDebugFileList &list);
159 bool loadDebugInfo(JDGDebugFileList &list, const char *filename, JDGCodInfo &info);
160 bool loadDebugInfo(JDGDebugFileList &list, const uint32_t uniqueId, const std::string module, JDGCodInfo &info);
163 } // namespace JDG
165 } // namespace Barry
168 #endif