Skip to content

Commit

Permalink
wip: working on fractional numbers interpretation
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Nov 5, 2024
1 parent c1cdcb4 commit 9491ffd
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 137 deletions.
2 changes: 1 addition & 1 deletion src/ConfigHandler/ConfigHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void ConfigHandler::loadVariables(std::map<std::string, std::shared_ptr<Variable
trackedName = name;
newVar->setTrackedName(trackedName);
newVar->setAddress(atoi(ini->get(varFieldFromID(varId)).get("address").c_str()));
newVar->setType(static_cast<Variable::type>(atoi(ini->get(varFieldFromID(varId)).get("type").c_str())));
newVar->setType(static_cast<Variable::Type>(atoi(ini->get(varFieldFromID(varId)).get("type").c_str())));
newVar->setColor(static_cast<uint32_t>(atol(ini->get(varFieldFromID(varId)).get("color").c_str())));
newVar->setShift(atoi(ini->get(varFieldFromID(varId)).get("shift").c_str()));

Expand Down
8 changes: 4 additions & 4 deletions src/GdbParser/GdbParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool GdbParser::updateVariableMap(const std::string& elfPath, std::map<std::stri
continue;

var->setIsFound(false);
var->setType(Variable::type::UNKNOWN);
var->setType(Variable::Type::UNKNOWN);

auto maybeAddress = checkAddress(var->getTrackedName());
if (!maybeAddress.has_value())
Expand Down Expand Up @@ -143,7 +143,7 @@ void GdbParser::checkVariableType(std::string& name)

std::string out;

if (checkType(name, &out) != Variable::type::UNKNOWN)
if (checkType(name, &out) != Variable::Type::UNKNOWN)
{
/* trivial type */
std::lock_guard<std::mutex> lock(mtx);
Expand Down Expand Up @@ -200,7 +200,7 @@ void GdbParser::checkVariableType(std::string& name)
}
}

Variable::type GdbParser::checkType(const std::string& name, std::string* output)
Variable::Type GdbParser::checkType(const std::string& name, std::string* output)
{
auto out = process.executeCmd(std::string("ptype ") + name + std::string("\n"), "(gdb)");
if (output != nullptr)
Expand All @@ -219,7 +219,7 @@ Variable::type GdbParser::checkType(const std::string& name, std::string* output
line.erase(0, 13);

if (!isTrivial.contains(line))
return Variable::type::UNKNOWN;
return Variable::Type::UNKNOWN;

return isTrivial.at(line);
}
Expand Down
66 changes: 33 additions & 33 deletions src/GdbParser/GdbParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GdbParser
private:
void parseVariableChunk(const std::string& chunk);
void checkVariableType(std::string& name);
Variable::type checkType(const std::string& name, std::string* output);
Variable::Type checkType(const std::string& name, std::string* output);
std::optional<uint32_t> checkAddress(const std::string& name);

private:
Expand All @@ -51,44 +51,44 @@ class GdbParser
std::map<std::string, VariableData> parsedData;
ProcessHandler process;

std::unordered_map<std::string, Variable::type> isTrivial = {
{"_Bool", Variable::type::U8},
{"bool", Variable::type::U8},
{"unsigned char", Variable::type::U8},
{"unsigned 8-bit", Variable::type::U8},
std::unordered_map<std::string, Variable::Type> isTrivial = {
{"_Bool", Variable::Type::U8},
{"bool", Variable::Type::U8},
{"unsigned char", Variable::Type::U8},
{"unsigned 8-bit", Variable::Type::U8},

{"char", Variable::type::I8},
{"signed char", Variable::type::I8},
{"signed 8-bit", Variable::type::I8},
{"char", Variable::Type::I8},
{"signed char", Variable::Type::I8},
{"signed 8-bit", Variable::Type::I8},

{"unsigned short", Variable::type::U16},
{"unsigned 16-bit", Variable::type::U16},
{"unsigned short int", Variable::type::U16},
{"short unsigned int", Variable::type::U16},
{"unsigned short", Variable::Type::U16},
{"unsigned 16-bit", Variable::Type::U16},
{"unsigned short int", Variable::Type::U16},
{"short unsigned int", Variable::Type::U16},

{"short", Variable::type::I16},
{"short int", Variable::type::I16},
{"signed short", Variable::type::I16},
{"signed 16-bit", Variable::type::I16},
{"signed short int", Variable::type::I16},
{"short signed int", Variable::type::I16},
{"short", Variable::Type::I16},
{"short int", Variable::Type::I16},
{"signed short", Variable::Type::I16},
{"signed 16-bit", Variable::Type::I16},
{"signed short int", Variable::Type::I16},
{"short signed int", Variable::Type::I16},

{"unsigned int", Variable::type::U32},
{"unsigned long", Variable::type::U32},
{"unsigned 32-bit", Variable::type::U32},
{"unsigned long int", Variable::type::U32},
{"long unsigned int", Variable::type::U32},
{"unsigned int", Variable::Type::U32},
{"unsigned long", Variable::Type::U32},
{"unsigned 32-bit", Variable::Type::U32},
{"unsigned long int", Variable::Type::U32},
{"long unsigned int", Variable::Type::U32},

{"int", Variable::type::I32},
{"long", Variable::type::I32},
{"long int", Variable::type::I32},
{"signed int", Variable::type::I32},
{"signed long", Variable::type::I32},
{"signed 32-bit", Variable::type::I32},
{"signed long int", Variable::type::I32},
{"long signed int", Variable::type::I32},
{"int", Variable::Type::I32},
{"long", Variable::Type::I32},
{"long int", Variable::Type::I32},
{"signed int", Variable::Type::I32},
{"signed long", Variable::Type::I32},
{"signed 32-bit", Variable::Type::I32},
{"signed long int", Variable::Type::I32},
{"long signed int", Variable::Type::I32},

{"float", Variable::type::F32},
{"float", Variable::Type::F32},
};
};
#endif
2 changes: 1 addition & 1 deletion src/Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ void Gui::showChangeFormatPopup(const char* text, Plot& plt, const std::string&
{
int format = static_cast<int>(plt.getSeriesDisplayFormat(name));

if (plt.getSeries(name)->var->getType() == Variable::type::F32)
if (plt.getSeries(name)->var->getType() == Variable::Type::F32)
return;

if (ImGui::BeginPopupContextItem(name.c_str()))
Expand Down
38 changes: 15 additions & 23 deletions src/Gui/GuiVariablesEdit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class VariableEditWindow
std::string shift = std::to_string(editedVariable->getShift());
std::string mask = std::string("0x") + std::string(GuiHelper::intToHexString(editedVariable->getMask()));
bool shouldUpdateFromElf = editedVariable->getShouldUpdateFromElf();
bool fractional = editedVariable->getIsFractional();
static bool selectNameManually = false;

ImGui::Dummy(ImVec2(-1, 5));
Expand Down Expand Up @@ -115,19 +114,15 @@ class VariableEditWindow
editedVariable->setAddress(addressDec);
}

GuiHelper::drawTextAlignedToSize("type:", alignment);
GuiHelper::drawTextAlignedToSize("base type:", alignment);
ImGui::SameLine();
int32_t type = static_cast<int32_t>(editedVariable->getType());

if (ImGui::Combo("##varType", &type, Variable::types, IM_ARRAYSIZE(Variable::types)))
{
editedVariable->setType(static_cast<Variable::type>(type));
editedVariable->setType(static_cast<Variable::Type>(type));
}

GuiHelper::drawTextAlignedToSize("size:", alignment);
ImGui::SameLine();
ImGui::InputText("##size", &size, 0, NULL, NULL);

ImGui::EndDisabled();

/* POSTPROCESSING */
Expand Down Expand Up @@ -156,39 +151,36 @@ class VariableEditWindow
GuiHelper::drawCenteredText("Interpretation");
ImGui::Separator();

GuiHelper::drawTextAlignedToSize("fractional:", alignment);
GuiHelper::drawTextAlignedToSize("type:", alignment);
ImGui::SameLine();
if (ImGui::Checkbox("##isfractional", &fractional))
int32_t highLeveltype = static_cast<int32_t>(editedVariable->getHighLevelType());

if (ImGui::Combo("##varHighLevelType", &highLeveltype, Variable::highLevelTypes, IM_ARRAYSIZE(Variable::highLevelTypes)))
{
editedVariable->setIsFractional(fractional);
editedVariable->setHighLevelType(static_cast<Variable::HighLevelType>(highLeveltype));
}

if (fractional)
if (editedVariable->getHighLevelType() == Variable::HighLevelType::SIGNEDFRAC || editedVariable->getHighLevelType() == Variable::HighLevelType::UNSIGNEDFRAC)
{
bool shouldUpdate = false;
Variable::Fractional fractional = editedVariable->getFractional();
std::string decimalBits = std::to_string(fractional.decimalBits);
std::string base = std::to_string(fractional.base);
std::string fractionalBits = std::to_string(fractional.fractionalBits);
bool shouldUpdate = false;

GuiHelper::drawTextAlignedToSize("sign:", alignment);
ImGui::SameLine();
if (ImGui::Checkbox("##sign", &fractional.sign))
shouldUpdate = true;

GuiHelper::drawTextAlignedToSize("decimal bits:", alignment);
GuiHelper::drawTextAlignedToSize("fractional bits:", alignment);
ImGui::SameLine();
if (ImGui::InputText("##decimal", &decimalBits, ImGuiInputTextFlags_CharsDecimal, NULL, NULL))
if (ImGui::InputText("##fractional", &fractionalBits, ImGuiInputTextFlags_CharsDecimal, NULL, NULL))
shouldUpdate = true;

GuiHelper::drawTextAlignedToSize("fractional bits:", alignment);
GuiHelper::drawTextAlignedToSize("base:", alignment);
ImGui::SameLine();
if (ImGui::InputText("##fractional", &fractionalBits, ImGuiInputTextFlags_CharsDecimal, NULL, NULL))
if (ImGui::InputText("##base", &base, ImGuiInputTextFlags_CharsDecimal, NULL, NULL))
shouldUpdate = true;

if (shouldUpdate)
{
fractional.decimalBits = GuiHelper::convertStringToNumber<uint32_t>(decimalBits);
fractional.fractionalBits = GuiHelper::convertStringToNumber<uint32_t>(fractionalBits);
fractional.base = GuiHelper::convertStringToNumber<double>(base);
editedVariable->setFractional(fractional);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/MemoryReader/MemoryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::optional<IDebugProbe::varEntryType> MemoryReader::readSingleEntry()
return probe->readSingleEntry();
}

uint32_t MemoryReader::getValue(uint32_t address, Variable::type type, bool& result)
uint32_t MemoryReader::getValue(uint32_t address, Variable::Type type, bool& result)
{
uint32_t value = 0;
std::lock_guard<std::mutex> lock(mtx);
Expand All @@ -35,7 +35,7 @@ uint32_t MemoryReader::getValue(uint32_t address, Variable::type type, bool& res
if (probe->requiresAlignedAccessOnRead())
{
uint8_t shouldShift = address % 4;
if (type == Variable::type::I8 || type == Variable::type::U8)
if (type == Variable::Type::I8 || type == Variable::Type::U8)
{
if (shouldShift == 0)
value = (value & 0x000000ff);
Expand All @@ -46,7 +46,7 @@ uint32_t MemoryReader::getValue(uint32_t address, Variable::type type, bool& res
else if (shouldShift == 3)
value = (value & 0xff000000) >> 24;
}
else if (type == Variable::type::I16 || type == Variable::type::U16)
else if (type == Variable::Type::I16 || type == Variable::Type::U16)
{
if (shouldShift == 0)
value = (value & 0x0000ffff);
Expand All @@ -57,7 +57,7 @@ uint32_t MemoryReader::getValue(uint32_t address, Variable::type type, bool& res
else if (shouldShift == 3)
value = (value & 0x000000ff) << 8 | (value & 0xff000000) >> 24;
}
else if (type == Variable::type::I32 || type == Variable::type::U32 || type == Variable::type::F32)
else if (type == Variable::Type::I32 || type == Variable::Type::U32 || type == Variable::Type::F32)
{
if (shouldShift == 1)
value = (value & 0x000000ff) << 24 | (value & 0xffffff00) >> 8;
Expand Down Expand Up @@ -89,19 +89,19 @@ bool MemoryReader::setValue(const Variable& var, double value)

switch (var.getType())
{
case Variable::type::U8:
case Variable::Type::U8:
return prepareBufferAndWrite(static_cast<uint8_t>(value), buf);
case Variable::type::I8:
case Variable::Type::I8:
return prepareBufferAndWrite(static_cast<int8_t>(value), buf);
case Variable::type::U16:
case Variable::Type::U16:
return prepareBufferAndWrite(static_cast<uint16_t>(value), buf);
case Variable::type::I16:
case Variable::Type::I16:
return prepareBufferAndWrite(static_cast<int16_t>(value), buf);
case Variable::type::U32:
case Variable::Type::U32:
return prepareBufferAndWrite(static_cast<uint32_t>(value), buf);
case Variable::type::I32:
case Variable::Type::I32:
return prepareBufferAndWrite(static_cast<int32_t>(value), buf);
case Variable::type::F32:
case Variable::Type::F32:
{
float valf = static_cast<float>(value);
uint32_t val = *reinterpret_cast<uint32_t*>(&valf);
Expand Down
2 changes: 1 addition & 1 deletion src/MemoryReader/MemoryReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MemoryReader

std::optional<IDebugProbe::varEntryType> readSingleEntry();

uint32_t getValue(uint32_t address, Variable::type type, bool& result);
uint32_t getValue(uint32_t address, Variable::Type type, bool& result);

bool setValue(const Variable& var, double value);
std::string getLastErrorMsg() const;
Expand Down
20 changes: 10 additions & 10 deletions src/Plot/Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ std::vector<uint32_t> Plot::getVariableAddesses() const
return addresses;
}

std::vector<Variable::type> Plot::getVariableTypes() const
std::vector<Variable::Type> Plot::getVariableTypes() const
{
std::vector<Variable::type> types;
std::vector<Variable::Type> types;
for (auto& [name, ser] : seriesMap)
types.push_back(ser->var->getType());

Expand Down Expand Up @@ -186,9 +186,9 @@ void Plot::setSeriesDisplayFormat(const std::string& name, displayFormat format)

std::string Plot::getSeriesValueString(const std::string& name, double value)
{
Variable::type type = seriesMap.at(name)->var->getType();
Variable::Type type = seriesMap.at(name)->var->getType();

if (type == Variable::type::F32)
if (type == Variable::Type::F32)
return std::to_string(value);

switch (seriesMap.at(name)->format)
Expand All @@ -205,20 +205,20 @@ std::string Plot::getSeriesValueString(const std::string& name, double value)
{
switch (type)
{
case Variable::type::I8:
case Variable::type::U8:
case Variable::Type::I8:
case Variable::Type::U8:
{
std::bitset<8> binaryValue(value);
return std::string("0b") + binaryValue.to_string();
}
case Variable::type::I16:
case Variable::type::U16:
case Variable::Type::I16:
case Variable::Type::U16:
{
std::bitset<16> binaryValue(value);
return std::string("0b") + binaryValue.to_string();
}
case Variable::type::I32:
case Variable::type::U32:
case Variable::Type::I32:
case Variable::Type::U32:
{
std::bitset<32> binaryValue(value);
return std::string("0b") + binaryValue.to_string();
Expand Down
2 changes: 1 addition & 1 deletion src/Plot/Plot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Plot
bool removeAllVariables();
void renameSeries(const std::string& oldName, const std::string newName);
std::vector<uint32_t> getVariableAddesses() const;
std::vector<Variable::type> getVariableTypes() const;
std::vector<Variable::Type> getVariableTypes() const;
bool addPoint(const std::string& varName, double value);
bool addTimePoint(double t);
void erase();
Expand Down
16 changes: 8 additions & 8 deletions src/PlotHandler/PlotHandlerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,23 @@ void PlotHandlerBase::setMaxPoints(uint32_t maxPoints)
}
}

double PlotHandlerBase::castToProperType(uint32_t value, Variable::type type)
double PlotHandlerBase::castToProperType(uint32_t value, Variable::Type type)
{
switch (type)
{
case Variable::type::U8:
case Variable::Type::U8:
return static_cast<double>(*reinterpret_cast<uint8_t*>(&value));
case Variable::type::I8:
case Variable::Type::I8:
return static_cast<double>(*reinterpret_cast<int8_t*>(&value));
case Variable::type::U16:
case Variable::Type::U16:
return static_cast<double>(*reinterpret_cast<uint16_t*>(&value));
case Variable::type::I16:
case Variable::Type::I16:
return static_cast<double>(*reinterpret_cast<int16_t*>(&value));
case Variable::type::U32:
case Variable::Type::U32:
return static_cast<double>(*reinterpret_cast<uint32_t*>(&value));
case Variable::type::I32:
case Variable::Type::I32:
return static_cast<double>(*reinterpret_cast<int32_t*>(&value));
case Variable::type::F32:
case Variable::Type::F32:
return static_cast<double>(*reinterpret_cast<float*>(&value));
default:
return static_cast<double>(*reinterpret_cast<uint32_t*>(&value));
Expand Down
4 changes: 2 additions & 2 deletions src/PlotHandler/PlotHandlerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class PlotHandlerBase
uint32_t getPlotsCount() const;
bool checkIfPlotExists(const std::string& name) const;
void setMaxPoints(uint32_t maxPoints);

/* TODO these functions do not belong here */
double castToProperType(uint32_t value, Variable::type type);
double castToProperType(uint32_t value, Variable::Type type);
uint32_t applyTransformations(uint32_t value, uint32_t shift, uint32_t mask);
class iterator
{
Expand Down
Loading

0 comments on commit 9491ffd

Please sign in to comment.