2024.8.17

This commit is contained in:
rootacite
2024-08-17 17:09:05 +08:00
committed by acite
parent 6d950b92f7
commit 4a7622807a
14 changed files with 1176 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build/

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

2
.idea/aldbg.iml generated Normal file
View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/aldbg.iml" filepath="$PROJECT_DIR$/.idea/aldbg.iml" />
</modules>
</component>
</project>

17
CMakeLists.txt Normal file
View File

@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.28)
project(aldbg)
set(CMAKE_CXX_STANDARD 20)
include_directories(.)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)
include_directories(${GTKMM_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS})
add_executable(aldbg
main.cpp cpu/cpu.cpp core/attach.cpp core/core.cpp log/log.cpp)
target_link_libraries(aldbg ${GTKMM_LIBRARIES})

850
aldbg.glade Normal file
View File

@@ -0,0 +1,850 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2
The MIT License (MIT)
Copyright (c)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<interface>
<requires lib="gtk+" version="3.24"/>
<!-- interface-license-type mit -->
<!-- interface-name aldug -->
<!-- interface-description Debuger with user interface in Linux -->
<object class="GtkListStore" id="codeView">
<columns>
<!-- column-name Address -->
<column type="gchararray"/>
<!-- column-name Data -->
<column type="gchararray"/>
<!-- column-name Disassembly -->
<column type="gchararray"/>
<!-- column-name Status -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="dialogAttach">
<property name="can-focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window-position">center-on-parent</property>
<property name="type-hint">dialog</property>
<property name="skip-taskbar-hint">True</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="dAttach">
<property name="label" translatable="yes">Attach</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="dCancel">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=8 n-rows=7 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">6</property>
<property name="column-spacing">5</property>
<child>
<object class="GtkLabel">
<property name="height-request">30</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">File Path:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="height-request">30</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Command Args:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="width-request">450</property>
<property name="height-request">30</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
<property name="width">6</property>
</packing>
</child>
<child>
<object class="GtkTextView">
<property name="width-request">450</property>
<property name="height-request">30</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">4</property>
<property name="width">6</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">7</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">7</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkListStore" id="logView">
<columns>
<!-- column-name Time -->
<column type="gchararray"/>
<!-- column-name Data -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="regView">
<columns>
<!-- column-name Registers -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow" id="MainWindow">
<property name="can-focus">False</property>
<property name="window-position">center-always</property>
<property name="default-width">1280</property>
<property name="default-height">720</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkStackSidebar" id="bar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stack">stack</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<child>
<!-- n-columns=15 n-rows=13 -->
<object class="GtkGrid" id="pageCPU">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="row-homogeneous">True</property>
<property name="column-homogeneous">True</property>
<child>
<object class="GtkTreeView" id="reg">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">regView</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="regViewRegisters">
<property name="title" translatable="yes">Registers</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">13</property>
<property name="top-attach">0</property>
<property name="width">2</property>
<property name="height">13</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="bRestart">
<property name="label" translatable="yes">Restart</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bStop">
<property name="label" translatable="yes">Stop</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bSuspend">
<property name="label" translatable="yes">Pause</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bCont">
<property name="label" translatable="yes">Continue</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bStepinto">
<property name="label" translatable="yes">Goin</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bStepNext">
<property name="label" translatable="yes">Next</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bTraceinto">
<property name="label" translatable="yes">Tracein</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bTracenext">
<property name="label" translatable="yes">Point</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">7</property>
</packing>
</child>
<child>
<object class="GtkButton" id="bEscape">
<property name="label" translatable="yes">Escape</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">8</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">13</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView" id="code">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">codeView</property>
<property name="search-column">0</property>
<property name="ubuntu-almost-fixed-height-mode">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="codeViewStatus">
<property name="title" translatable="yes">Status</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="codeViewAddress">
<property name="min-width">100</property>
<property name="title" translatable="yes">Address</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="codeViewData">
<property name="min-width">100</property>
<property name="title" translatable="yes">Data</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="codeViewDisa">
<property name="title" translatable="yes">Disassembly</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
<property name="width">13</property>
<property name="height">9</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView" id="mem">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="tooltip-column">2</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">column</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">column</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">10</property>
<property name="width">13</property>
<property name="height">3</property>
</packing>
</child>
</object>
<packing>
<property name="name">CPU</property>
<property name="title" translatable="yes">CPU</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="pageMemory">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">Memory</property>
<property name="title" translatable="yes">Memory</property>
<property name="position">1</property>
</packing>
</child>
<child>
<!-- n-columns=1 n-rows=1 -->
<object class="GtkGrid" id="pageLog">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView" id="log">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">logView</property>
<property name="search-column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="TimeCol">
<property name="min-width">85</property>
<property name="title" translatable="yes">Time</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="DataCol">
<property name="title" translatable="yes">Data</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="name">Log</property>
<property name="title" translatable="yes">Log</property>
<property name="position">2</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="pageBreakpoints">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">Breakpoints</property>
<property name="title" translatable="yes">Breakpoints</property>
<property name="position">3</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="pageCall">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">Call Stack</property>
<property name="title" translatable="yes">Call Stack</property>
<property name="position">4</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="pageSymbols">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">Symbols</property>
<property name="title" translatable="yes">Symbols</property>
<property name="position">5</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Aldbg x64</property>
<property name="show-close-button">True</property>
<child>
<object class="GtkButton" id="bAttach">
<property name="label" translatable="yes">Attach</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
</child>
</object>
</child>
</object>
</interface>

26
core/attach.cpp Normal file
View File

@@ -0,0 +1,26 @@
//
// Created by acite on 5/1/24.
//
#include <gtkmm.h>
using namespace Gtk;
extern Button* bAttach;
extern Dialog* dialogAttach;
extern Window* MainWindow;
void button_attach()
{
dialogAttach->show();
}
void button_exec()
{
int fk = fork();
if(fk == 0)
{
execl("/usr/bin/netstat", "netstat" ,"-tupln", NULL);
return;
}
}

4
core/core.cpp Normal file
View File

@@ -0,0 +1,4 @@
//
// Created by acite on 5/1/24.
//

39
cpu/cpu.cpp Normal file
View File

@@ -0,0 +1,39 @@
//
// Created by acite on 5/1/24.
//
#include "cpu.h"
using namespace std;
using namespace Gtk;
extern TreeView* codeView;
extern Glib::RefPtr<ListStore> codeViewStore;
void add_row(const string& addr,
const string& data,
const string& dasm,
const string& sts
){
auto mm = codeViewStore->append();
Gtk::TreeModel::Row row = *mm;
row.set_value(0, addr);
row.set_value(1, data);
row.set_value(2, dasm);
row.set_value(3, sts);
}
void set_row_status(uint64_t index_addr, const string& sts)
{
string addr;
for(auto i : codeViewStore->children())
{
i.get_value(0, addr);
if(to_string(index_addr) == addr)
{
i.set_value(3, sts);
break;
}
}
}

20
cpu/cpu.h Normal file
View File

@@ -0,0 +1,20 @@
//
// Created by acite on 5/1/24.
//
#ifndef ALDBG_CPU_H
#define ALDBG_CPU_H
#include <gtkmm.h>
#include <iostream>
#include <string>
void add_row(const std::string &addr,
const std::string &data,
const std::string &dasm,
const std::string &sts
);
void set_row_status(uint64_t index_addr, const std::string& sts);
#endif //ALDBG_CPU_H

33
log/log.cpp Normal file
View File

@@ -0,0 +1,33 @@
//
// Created by acite on 5/1/24.
//
#include <ctime>
#include <cstring>
#include <gtkmm.h>
#include <unistd.h>
#include <fcntl.h>
#include "log.h"
#include <pthread.h>
using namespace Gtk;
using namespace std;
extern Glib::RefPtr<ListStore> logStore;
void add_log_data(const std::string& data)
{
auto mm = logStore->append();
Gtk::TreeModel::Row row = *mm;
time_t currentTime;
time(&currentTime);
tm* localTime = localtime(&currentTime);
char time_str[64];
sprintf(time_str, "[%d:%d:%d]", localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
string cppstrtime = time_str;
row.set_value(0, cppstrtime);
row.set_value(1, data);
}

12
log/log.h Normal file
View File

@@ -0,0 +1,12 @@
//
// Created by acite on 5/1/24.
//
#ifndef ALDBG_LOG_H
#define ALDBG_LOG_H
#include <string>
void add_log_data(const std::string& data);
#endif //ALDBG_LOG_H

149
main.cpp Normal file
View File

@@ -0,0 +1,149 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <gtkmm.h>
#include <iostream>
#include <string>
#include <pthread.h>
#include <sys/wait.h>
#include "cpu/cpu.h"
#include "log/log.h"
#define MAX_LOG_BUFFER_SIZE (1024*1024)
using namespace std;
using namespace Gtk;
extern void button_attach();
extern void button_exec();
TreeView* codeView;
TreeView* logView;
Glib::RefPtr<ListStore> codeViewStore;
Glib::RefPtr<ListStore> logStore;
Button* bAttach;
Dialog* dialogAttach;
Button* dCancel;
Button* dAttach;
Button* bStop;
Window* MainWindow = nullptr;
static Glib::RefPtr<Application> app;
static pthread_t threads[5];
epoll_event events[5] = {
{ .events = EPOLLIN } // Event for pipe data
};
epoll_event r_events[5] = {0};
char buffer[MAX_LOG_BUFFER_SIZE];
ssize_t sz = -1;
int pipefd[2] = {0};
void *aldbg_io_handler(void *arg)
{
int r = pipe2(pipefd, O_CLOEXEC | O_NONBLOCK);
if(r == -1)
{
perror("pipe2()");
return nullptr;
}
dup2(pipefd[1], 1); // dup pipe write port to stdout
events[0].data.fd = pipefd[0];
int efd = epoll_create1(0);
epoll_ctl(efd, EPOLL_CTL_ADD, pipefd[0], &events[0]);
while(1)
{
r = epoll_wait(efd, r_events, 5, 2000);
if(r == -1)perror("epoll_wait()");
if(r == 0)continue;
for(int i=0;i<r;i++)
{
if(r_events[i].data.fd == pipefd[0])
{
sz = read(pipefd[0], buffer, MAX_LOG_BUFFER_SIZE);
buffer[sz] = 0;
char *pStr = strtok(buffer, "\n");
while(pStr)
{
add_log_data(pStr);
pStr = strtok(NULL, "\n");
}
}
}
}
return nullptr;
}
bool motion_event(GdkEventMotion* m)
{
double x = m->x;
double y = m->y;
std::cout << "Mouse moved to: (" << x << ", " << y << ")" << std::endl;
return false; // 事件已被处理
}
void window_init()
{
////////////////////////////////////////// register assemblies
auto builder = Builder::create_from_file("../aldbg.glade");
builder->get_widget("MainWindow", MainWindow);
builder->get_widget("code", codeView);
builder->get_widget("log", logView);
builder->get_widget("bAttach", bAttach);
builder->get_widget("dialogAttach", dialogAttach);
builder->get_widget("dCancel", dCancel);
builder->get_widget("dAttach", dAttach);
builder->get_widget("bStop", bStop);
codeViewStore = Glib::RefPtr<Gtk::ListStore>::cast_dynamic(codeView->get_model());
logStore = Glib::RefPtr<Gtk::ListStore>::cast_dynamic(logView->get_model());
///////////////////////////////////////////
app->add_window(*MainWindow);
MainWindow->show(); // Show Window
for(int i=0;i<35;i++)
add_row(to_string(i * 1000), "DAF", "Fuck", "->");
set_row_status(2000, "*->");
///////////////////////////////////////////////////// register events
bAttach->signal_clicked().connect([](){
button_attach();
});
dCancel->signal_clicked().connect([](){
dialogAttach->close();
});
dAttach->signal_clicked().connect([](){
button_exec();
});
bStop->signal_clicked().connect([](){
});
MainWindow->add_events(Gdk::POINTER_MOTION_MASK);
/////////////////////////////////////////////////////
pthread_create(&threads[0], nullptr, aldbg_io_handler, nullptr);
}
int main()
{
app = Application::create();
app->signal_activate().connect([](){
window_init();
});
return app->run();
}