Skip to content

Commit

Permalink
-Link namespaces to symbols. WIP.
Browse files Browse the repository at this point in the history
-Add unit testing for namespacing. WIP.
  • Loading branch information
lorenzo-gomez-windhover committed Jan 10, 2025
1 parent 8a308e5 commit b2f6c14
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 91 deletions.
5 changes: 3 additions & 2 deletions src/ElfFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Symbol* ElfFile::getSymbol(std::string& name)
return returnSymbol;
}

Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact newArtifact, Symbol* targetSymbol)
Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact newArtifact, Symbol* targetSymbol, Namespace* symbolNamepace)
{
Symbol* symbol = getSymbol(inName);

Expand All @@ -102,13 +102,14 @@ Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact ne
return symbol;
}

Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact newArtifact)
Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact newArtifact, Namespace* symbolNamepace)
{
Symbol* symbol = getSymbol(inName);

if (symbol == nullptr)
{
std::unique_ptr<Symbol> newSymbol = std::make_unique<Symbol>(*this, inName, inByteSize, newArtifact);
newSymbol->setNamespace(symbolNamepace);

symbols.push_back(std::move(newSymbol));

Expand Down
38 changes: 19 additions & 19 deletions src/ElfFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ class ElfFile
public:
ElfFile(std::string &name);
virtual ~ElfFile();
std::vector<std::unique_ptr<Symbol>> &getSymbols();

std::string getName() const;
uint32_t getId(void) const;
void setId(uint32_t newId);
Symbol *addSymbol(std::string &name, uint32_t byte_size, Artifact newArtifact);
Symbol *addSymbol(std::string &inName, uint32_t inByteSize, Artifact newArtifact, Symbol *targetSymbol);
std::vector<Field *> getFields();
std::vector<Enumeration *> getEnumerations();
Symbol *getSymbol(std::string &name);
const std::string &getDate() const;
void setDate(const std::string &date);
bool isLittleEndian() const;
void isLittleEndian(bool littleEndian);
void setMD5(std::string newID);
std::string getMD5() const;
void addDefineMacro(DefineMacro newMacro);

const std::vector<DefineMacro> &getDefineMacros() const;
std::vector<std::unique_ptr<Symbol>> &getSymbols();

std::string getName() const;
uint32_t getId(void) const;
void setId(uint32_t newId);
Symbol *addSymbol(std::string &name, uint32_t byte_size, Artifact newArtifact, Namespace *symbolNamepace);
Symbol *addSymbol(std::string &inName, uint32_t inByteSize, Artifact newArtifact, Symbol *targetSymbol, Namespace *symbolNamepace);
std::vector<Field *> getFields();
std::vector<Enumeration *> getEnumerations();
Symbol *getSymbol(std::string &name);
const std::string &getDate() const;
void setDate(const std::string &date);
bool isLittleEndian() const;
void isLittleEndian(bool littleEndian);
void setMD5(std::string newID);
std::string getMD5() const;
void addDefineMacro(DefineMacro newMacro);

const std::vector<DefineMacro> &getDefineMacros() const;

const std::map<std::string, std::vector<uint8_t>> &getInitializedSymbolData() const;

Expand Down
92 changes: 46 additions & 46 deletions src/Juicer.cpp

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/Juicer.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ class Juicer
Dwarf_Ptr errarg = 0;
int readCUList(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Error& error);
int getDieAndSiblings(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die in_die, int in_level, Namespace* currentNamespace);
Symbol* process_DW_TAG_typedef(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die in_die);
Symbol* process_DW_TAG_base_type(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die in_die);
void process_DW_TAG_structure_type(ElfFile& elf, Symbol& symbol, Dwarf_Debug dbg, Dwarf_Die inDie);
Symbol* process_DW_TAG_pointer_type(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die inDie);
Symbol* process_DW_TAG_variable_type(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die inDie);
Symbol* process_DW_TAG_typedef(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die in_die, Namespace* currentNamespace);
Symbol* process_DW_TAG_base_type(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die in_die, Namespace* currentNamespace);
void process_DW_TAG_structure_type(ElfFile& elf, Symbol& symbol, Dwarf_Debug dbg, Dwarf_Die inDie, Namespace* currentNamespace);
Symbol* process_DW_TAG_pointer_type(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die inDie, Namespace* currentNamespace);
Symbol* process_DW_TAG_variable_type(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die inDie, Namespace* currentNamespace);
void process_DW_TAG_enumeration_type(ElfFile& elf, Symbol& symbol, Dwarf_Debug dbg, Dwarf_Die inDie);
int process_DW_TAG_array_type(ElfFile& elf, Symbol& symbol, Dwarf_Debug dbg, Dwarf_Die inDie);
void process_DW_TAG_union_type(ElfFile& elf, Symbol& symbol, Dwarf_Debug dbg, Dwarf_Die inDie);
int process_DW_TAG_array_type(ElfFile& elf, Symbol& symbol, Dwarf_Debug dbg, Dwarf_Die inDie, Namespace* currentNamespace);
void process_DW_TAG_union_type(ElfFile& elf, Symbol& symbol, Dwarf_Debug dbg, Dwarf_Die inDie, Namespace* currentNamespace);
Namespace* process_DW_TAG_namespace(ElfFile& elf, Dwarf_Debug dbg, Dwarf_Die inDie, int in_level, Namespace* currentNamespace);
char* getFirstAncestorName(Dwarf_Die inDie);
int printDieData(Dwarf_Debug dbg, Dwarf_Die print_me, uint32_t level);
Expand All @@ -133,7 +133,7 @@ class Juicer
Logger logger;
IDataContainer* idc = 0;
bool isIDCSet(void);
Symbol* getBaseTypeSymbol(ElfFile& elf, Dwarf_Die inDie, DimensionList& multiplicity);
Symbol* getBaseTypeSymbol(ElfFile& elf, Dwarf_Die inDie, DimensionList& dimList, Namespace* currentNamespace);
void DisplayDie(Dwarf_Die inDie, uint32_t level);

std::vector<Dwarf_Die> getChildrenVector(Dwarf_Debug dbg, Dwarf_Die die);
Expand Down
59 changes: 49 additions & 10 deletions src/SQLiteDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ int SQLiteDB::write(ElfFile& inElf)
else
{
logger.logDebug(
"There was an error while writing macro entries to the"
"There was an error while writing Artifact entries to the"
" database.");
rc = SQLITEDB_ERROR;
}
Expand All @@ -333,13 +333,29 @@ int SQLiteDB::write(ElfFile& inElf)
if (SQLITEDB_ERROR != rc)
{
logger.logDebug(
"Variable entries were written to the variables schema "
"Encoding entries were written to the Encodings schema "
"with SQLITE_OK status.");

rc = writeAllNamespacesToDatabase(inElf);

if (SQLITEDB_ERROR != rc)
{
logger.logDebug(
"Namespace entries were written to the namespaces schema "
"with SQLITE_OK status.");
}
else
{
logger.logDebug(
"There was an error while writing namespace entries to the"
" database.");
rc = SQLITEDB_ERROR;
}
}
else
{
logger.logDebug(
"There was an error while writing variable entries to the"
"There was an error while writing Encoding entries to the"
" database.");
rc = SQLITEDB_ERROR;
}
Expand All @@ -354,14 +370,28 @@ int SQLiteDB::write(ElfFile& inElf)

rc = writeFieldsToDatabase(inElf);

writeDimensionsListToDatabase(inElf);

if (SQLITEDB_ERROR != rc)
{
logger.logDebug(
"Field entries were written to the fields schema "
"with SQLITE_OK status.");

rc = writeDimensionsListToDatabase(inElf);

if (SQLITEDB_ERROR != rc)
{
logger.logDebug(
"Field entries were written to the dimension_lists schema "
"with SQLITE_OK status.");
}
else
{
logger.logDebug(
"There was an error while writing dimension_lists entries to the"
" database.");
rc = SQLITEDB_ERROR;
}

rc = writeEnumerationsToDatabase(inElf);

if (SQLITEDB_ERROR != rc)
Expand All @@ -383,18 +413,16 @@ int SQLiteDB::write(ElfFile& inElf)
if (SQLITEDB_ERROR != rc)
{
logger.logDebug(
"Variable entries were written to the variables schema "
"Elf Sections were written to the variables schema "
"with SQLITE_OK status.");

rc = writeElfSymboltableSymbolsToDatabase(inElf);

if (SQLITEDB_ERROR != rc)
{
logger.logDebug(
"Variable entries were written to the variables schema "
"Elf Symbol Table Symbols entries were written to the variables schema "
"with SQLITE_OK status.");

rc = writeAllNamespacesToDatabase(inElf);
}
else
{
Expand Down Expand Up @@ -1184,7 +1212,7 @@ int SQLiteDB::writeSymbolsToDatabase(ElfFile& inElf)
if (!symbol->getEncoding())
{
writeSymbolQuery +=
"INSERT INTO symbols(elf, name, byte_size, artifact, long_description, short_description) "
"INSERT INTO symbols(elf, name, byte_size, artifact, namespace, long_description, short_description) "
"VALUES(";
writeSymbolQuery += std::to_string(symbol->getElf().getId());
writeSymbolQuery += ",\"";
Expand All @@ -1195,6 +1223,17 @@ int SQLiteDB::writeSymbolsToDatabase(ElfFile& inElf)
writeSymbolQuery += ",";
writeSymbolQuery += std::to_string(symbol->getArtifact().getId());

writeSymbolQuery += ",";

if (symbol->getNamespace() != nullptr)
{
writeSymbolQuery += std::to_string(symbol->getNamespace()->getId().value());
}
else
{
writeSymbolQuery += "-1";
}

writeSymbolQuery += ",\"";
writeSymbolQuery += symbol->getLongDescription();

Expand Down
2 changes: 2 additions & 0 deletions src/SQLiteDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
artifact INTEGER,\
target_symbol INTEGER,\
encoding INTEGER,\
namespace INTEGER,\
short_description TEXT ,\
long_description TEXT ,\
FOREIGN KEY(elf) REFERENCES elfs(id),\
FOREIGN KEY(artifact) REFERENCES artifacts(id)\
FOREIGN KEY(target_symbol) REFERENCES symbols(id)\
FOREIGN KEY(encoding) REFERENCES encodings(id)\
FOREIGN KEY(namespace) REFERENCES namespaces(id)\
UNIQUE(name));"

#define CREATE_DIMENSION_TABLE \
Expand Down
7 changes: 7 additions & 0 deletions src/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Enumeration.h"
#include "Field.h"
#include "Logger.h"
#include "Namespace.hpp"

class Field;
class Enumeration;
Expand Down Expand Up @@ -73,6 +74,10 @@ class Symbol

std::optional<int> getEncoding();

void setNamespace(Namespace *newNamespace) { namespace_ = newNamespace; }

Namespace *getNamespace() { return namespace_; }

private:
ElfFile &elf;
std::string name;
Expand All @@ -88,6 +93,8 @@ class Symbol
std::string long_description;

std::optional<int> encoding{std::nullopt};

Namespace *namespace_{nullptr};
};

#endif /* SYMBOL_H_ */
Loading

0 comments on commit b2f6c14

Please sign in to comment.