From fdb657ffe99da163970ef8a64d65f8ddc79f476a Mon Sep 17 00:00:00 2001 From: Shubh942 <93862397+Shubh942@users.noreply.github.com> Date: Tue, 11 Jun 2024 19:26:04 +0530 Subject: [PATCH 1/7] Added more Gdb Apis --- gdbui_server/flask_test.py | 75 +++++++++++++++---- gdbui_server/main.py | 147 +++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 16 deletions(-) diff --git a/gdbui_server/flask_test.py b/gdbui_server/flask_test.py index 03fe070..b10cd9d 100644 --- a/gdbui_server/flask_test.py +++ b/gdbui_server/flask_test.py @@ -1,10 +1,9 @@ import unittest import json import tempfile -import os from flask import Flask -from flask_testing import TestCase # type: ignore -from main import app +from flask_testing import TestCase +from main import app class TestGDBRoutes(TestCase): def create_app(self): @@ -12,35 +11,23 @@ def create_app(self): return app def setUp(self): - # Create a temporary directory for compiling C++ programs self.temp_dir = tempfile.TemporaryDirectory() - # Compile a simple C++ program for testing compile_payload = { "code": "#include \nint main() { std::cout << 'Hello, World!'; return 0; }", "name": "test_program", - "temp_dir": self.temp_dir.name # Pass the temporary directory path } self.client.post('/compile', data=json.dumps(compile_payload), content_type='application/json') def tearDown(self): - # Clean up the temporary directory self.temp_dir.cleanup() def test_compile_code(self): - # Create a temporary directory for compiling the test program - temp_dir = tempfile.TemporaryDirectory() - payload = { "code": "#include \nint main() { std::cout << 'Hello, Universe!'; return 0; }", "name": "test_program2", - "temp_dir": temp_dir.name # Pass the temporary directory path } response = self.client.post('/compile', data=json.dumps(payload), content_type='application/json') - - # Clean up the temporary directory - temp_dir.cleanup() - self.assertEqual(response.status_code, 200) self.assertTrue(response.json['success']) @@ -118,11 +105,67 @@ def test_run_program(self): def test_memory_map(self): memory_map_payload = { - "name": "test_program" + "name": "test_program" } response = self.client.post('/memory_map', data=json.dumps(memory_map_payload), content_type='application/json') self.assertEqual(response.status_code, 200) self.assertTrue(response.json['success']) + def test_continue_execution(self): + continue_payload = { + "name": "test_program" + } + response = self.client.post('/continue', data=json.dumps(continue_payload), content_type='application/json') + self.assertEqual(response.status_code, 200) + self.assertTrue(response.json['success']) + + def test_step_over(self): + step_over_payload = { + "name": "test_program" + } + response = self.client.post('/step_over', data=json.dumps(step_over_payload), content_type='application/json') + self.assertEqual(response.status_code, 200) + self.assertTrue(response.json['success']) + + def test_step_into(self): + step_into_payload = { + "name": "test_program" + } + response = self.client.post('/step_into', data=json.dumps(step_into_payload), content_type='application/json') + self.assertEqual(response.status_code, 200) + self.assertTrue(response.json['success']) + + def test_step_out(self): + step_out_payload = { + "name": "test_program" + } + response = self.client.post('/step_out', data=json.dumps(step_out_payload), content_type='application/json') + self.assertEqual(response.status_code, 200) + self.assertTrue(response.json['success']) + + def test_add_watchpoint(self): + add_watchpoint_payload = { + "variable": "var", + "name": "test_program" + } + response = self.client.post('/add_watchpoint', data=json.dumps(add_watchpoint_payload), content_type='application/json') + self.assertEqual(response.status_code, 200) + self.assertTrue(response.json['success']) + + def test_delete_breakpoint(self): + set_breakpoint_payload = { + "location": "main", + "name": "test_program" + } + self.client.post('/set_breakpoint', data=json.dumps(set_breakpoint_payload), content_type='application/json') + + delete_breakpoint_payload = { + "breakpoint_number": 1, + "name": "test_program" + } + response = self.client.post('/delete_breakpoint', data=json.dumps(delete_breakpoint_payload), content_type='application/json') + self.assertEqual(response.status_code, 200) + self.assertTrue(response.json['success']) + if __name__ == '__main__': unittest.main() diff --git a/gdbui_server/main.py b/gdbui_server/main.py index be7729d..5373f0e 100644 --- a/gdbui_server/main.py +++ b/gdbui_server/main.py @@ -278,5 +278,152 @@ def memory_map(): return jsonify(response) +@app.route('/continue', methods=['POST']) +def continue_execution(): + global program_name + data = request.get_json() + file = data.get('name') + if program_name != file: + start_gdb_session(f'{file}') + + try: + result = execute_gdb_command("continue") + response = { + 'success': True, + 'result': result, + 'code': "execute_gdb_command('continue')" + } + except Exception as e: + response = { + 'success': False, + 'error': str(e), + 'code': "execute_gdb_command('continue')" + } + + return jsonify(response) + +@app.route('/step_over', methods=['POST']) +def step_over(): + global program_name + data = request.get_json() + file = data.get('name') + if program_name != file: + start_gdb_session(f'{file}') + + try: + result = execute_gdb_command("next") + response = { + 'success': True, + 'result': result, + 'code': "execute_gdb_command('next')" + } + except Exception as e: + response = { + 'success': False, + 'error': str(e), + 'code': "execute_gdb_command('next')" + } + + return jsonify(response) + +@app.route('/step_into', methods=['POST']) +def step_into(): + global program_name + data = request.get_json() + file = data.get('name') + if program_name != file: + start_gdb_session(f'{file}') + + try: + result = execute_gdb_command("step") + response = { + 'success': True, + 'result': result, + 'code': "execute_gdb_command('step')" + } + except Exception as e: + response = { + 'success': False, + 'error': str(e), + 'code': "execute_gdb_command('step')" + } + + return jsonify(response) + +@app.route('/step_out', methods=['POST']) +def step_out(): + global program_name + data = request.get_json() + file = data.get('name') + if program_name != file: + start_gdb_session(f'{file}') + + try: + result = execute_gdb_command("finish") + response = { + 'success': True, + 'result': result, + 'code': "execute_gdb_command('finish')" + } + except Exception as e: + response = { + 'success': False, + 'error': str(e), + 'code': "execute_gdb_command('finish')" + } + + return jsonify(response) + +@app.route('/add_watchpoint', methods=['POST']) +def add_watchpoint(): + global program_name + data = request.get_json() + variable = data.get('variable') + file = data.get('name') + if program_name != file: + start_gdb_session(f'{file}') + + try: + result = execute_gdb_command(f"watch {variable}") + response = { + 'success': True, + 'result': result, + 'code': f"execute_gdb_command('watch {variable}')" + } + except Exception as e: + response = { + 'success': False, + 'error': str(e), + 'code': f"execute_gdb_command('watch {variable}')" + } + + return jsonify(response) + +@app.route('/delete_breakpoint', methods=['POST']) +def delete_breakpoint(): + global program_name + data = request.get_json() + breakpoint_number = data.get('breakpoint_number') + file = data.get('name') + if program_name != file: + start_gdb_session(f'{file}') + + try: + result = execute_gdb_command(f"delete {breakpoint_number}") + response = { + 'success': True, + 'result': result, + 'code': f"execute_gdb_command('delete {breakpoint_number}')" + } + except Exception as e: + response = { + 'success': False, + 'error': str(e), + 'code': f"execute_gdb_command('delete {breakpoint_number}')" + } + + return jsonify(response) + + if __name__ == '__main__': app.run(host='0.0.0.0', port=10000) From 829fab38b82c8a220dd8295b02749f83d028fbad Mon Sep 17 00:00:00 2001 From: Shubh942 <93862397+Shubh942@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:20:10 +0530 Subject: [PATCH 2/7] Added issue template and pull request template --- .github/ISSUE_TEMPLATE/1-bug-report.md | 78 +++++++++++++++++++ .github/ISSUE_TEMPLATE/2-feature-request.md | 41 ++++++++++ .../ISSUE_TEMPLATE/3-enhancement-request.md | 41 ++++++++++ .github/pull_request_template.md | 27 +++++++ 4 files changed, 187 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/1-bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/2-feature-request.md create mode 100644 .github/ISSUE_TEMPLATE/3-enhancement-request.md create mode 100644 .github/pull_request_template.md diff --git a/.github/ISSUE_TEMPLATE/1-bug-report.md b/.github/ISSUE_TEMPLATE/1-bug-report.md new file mode 100644 index 0000000..d2f8fb7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/1-bug-report.md @@ -0,0 +1,78 @@ +--- +name: "🐞 Bug Report" +about: "Report an issue to help the project improve." +title: "[Bug] " +labels: "Type: Bug" +--- + +# **🐞 Bug Report** + +## **Describe the bug** + + + +- *** + +### **Is this a regression?** + + + + +--- + +### **To Reproduce** + + + + + +1. +2. +3. +4. + +--- + +### **Expected behaviour** + + + +- *** + +### **Media prove** + + + +--- + +### **Your environment** + + + +- OS: +- Node version: +- Npm version: +- Browser name and version: + +--- + +### **Additional context** + + + +- + + diff --git a/.github/ISSUE_TEMPLATE/2-feature-request.md b/.github/ISSUE_TEMPLATE/2-feature-request.md new file mode 100644 index 0000000..cd758a5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/2-feature-request.md @@ -0,0 +1,41 @@ +--- +name: "🚀🆕 Feature Request" +about: "Suggest an idea or possible new feature for this project." +title: "" +labels: "Type: Feature" +--- + +# **🚀 Feature Request** + +## **Is your feature request related to a problem? Please describe.** + + + +- *** + +## **Describe the solution you'd like** + + + +- *** + +## **Describe alternatives you've considered** + + + +- *** + +### **Additional context** + + + +- + + diff --git a/.github/ISSUE_TEMPLATE/3-enhancement-request.md b/.github/ISSUE_TEMPLATE/3-enhancement-request.md new file mode 100644 index 0000000..44a9dd9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/3-enhancement-request.md @@ -0,0 +1,41 @@ +--- +name: "🚀➕ Enhancement Request" +about: "Suggest an enhancement for this project. Improve an existing feature" +title: "" +labels: "Type: Enhancement" +--- + +# **🚀 Enhancement Request** + +## **Is your enhancement request related to a problem? Please describe.** + + + +- *** + +## **Describe the solution you'd like** + + + +- *** + +## **Describe alternatives you've considered** + + + +- *** + +### **Additional context** + + + +- + + diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..26b7090 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,27 @@ +# **Name of PR** + + + +## **Description** + + + +- *** + +### **Additional context** + + + +- + + From 5f710499dd77825f0a85ea694c3c53637aa3902d Mon Sep 17 00:00:00 2001 From: Shubh942 <93862397+Shubh942@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:42:57 +0530 Subject: [PATCH 3/7] changes in github workflow and testcases --- .github/workflows/run-test.yml | 2 +- gdbui_server/flask_test.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 5523e7a..8d1c453 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt + pip install -r gdbui_server/requirements.txt - name: Run tests on changes run: | diff --git a/gdbui_server/flask_test.py b/gdbui_server/flask_test.py index b10cd9d..b9e7805 100644 --- a/gdbui_server/flask_test.py +++ b/gdbui_server/flask_test.py @@ -2,7 +2,7 @@ import json import tempfile from flask import Flask -from flask_testing import TestCase +from flask_testing import TestCase from main import app class TestGDBRoutes(TestCase): @@ -23,14 +23,18 @@ def tearDown(self): self.temp_dir.cleanup() def test_compile_code(self): + temp_dir = tempfile.TemporaryDirectory() + payload = { "code": "#include \nint main() { std::cout << 'Hello, Universe!'; return 0; }", "name": "test_program2", } response = self.client.post('/compile', data=json.dumps(payload), content_type='application/json') + temp_dir.cleanup() + self.assertEqual(response.status_code, 200) self.assertTrue(response.json['success']) - + def test_gdb_command(self): gdb_payload = { "command": "info locals", From 9d44cbee596a16adc4ea9e6600b18279c387ba9a Mon Sep 17 00:00:00 2001 From: Shubh942 <93862397+Shubh942@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:48:06 +0530 Subject: [PATCH 4/7] changes in yml file --- .github/workflows/run-test.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 8d1c453..19fee47 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -10,8 +10,15 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Checkout target branch uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.base.ref }} + + - name: Fetch pull request changes + run: | + git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge:pr + git checkout pr - name: Set up Python uses: actions/setup-python@v2 @@ -25,6 +32,4 @@ jobs: - name: Run tests on changes run: | - git fetch origin ${{ github.event.pull_request.head.ref }} - git checkout FETCH_HEAD python -m unittest discover -s gdbui_server -p 'flask_test.py' From 5065efbef776a0b8f7bd6c3a920c32705c46b42a Mon Sep 17 00:00:00 2001 From: Shubh942 <93862397+Shubh942@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:00:18 +0530 Subject: [PATCH 5/7] changes in test file --- gdbui_server/flask_test.py | 41 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/gdbui_server/flask_test.py b/gdbui_server/flask_test.py index b9e7805..3f4c5de 100644 --- a/gdbui_server/flask_test.py +++ b/gdbui_server/flask_test.py @@ -15,7 +15,7 @@ def setUp(self): compile_payload = { "code": "#include \nint main() { std::cout << 'Hello, World!'; return 0; }", - "name": "test_program", + "name": f"{self.temp_dir.name}/test_program", } self.client.post('/compile', data=json.dumps(compile_payload), content_type='application/json') @@ -23,14 +23,11 @@ def tearDown(self): self.temp_dir.cleanup() def test_compile_code(self): - temp_dir = tempfile.TemporaryDirectory() - payload = { "code": "#include \nint main() { std::cout << 'Hello, Universe!'; return 0; }", - "name": "test_program2", + "name": f"{self.temp_dir.name}/test_program2", } response = self.client.post('/compile', data=json.dumps(payload), content_type='application/json') - temp_dir.cleanup() self.assertEqual(response.status_code, 200) self.assertTrue(response.json['success']) @@ -38,7 +35,7 @@ def test_compile_code(self): def test_gdb_command(self): gdb_payload = { "command": "info locals", - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/gdb_command', data=json.dumps(gdb_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -47,7 +44,7 @@ def test_gdb_command(self): def test_set_breakpoint(self): breakpoint_payload = { "location": "main", - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/set_breakpoint', data=json.dumps(breakpoint_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -56,12 +53,12 @@ def test_set_breakpoint(self): def test_info_breakpoints(self): breakpoint_payload = { "location": "main", - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } self.client.post('/set_breakpoint', data=json.dumps(breakpoint_payload), content_type='application/json') info_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/info_breakpoints', data=json.dumps(info_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -69,7 +66,7 @@ def test_info_breakpoints(self): def test_stack_trace(self): stack_trace_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/stack_trace', data=json.dumps(stack_trace_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -77,7 +74,7 @@ def test_stack_trace(self): def test_threads(self): threads_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/threads', data=json.dumps(threads_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -85,7 +82,7 @@ def test_threads(self): def test_get_registers(self): get_registers_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/get_registers', data=json.dumps(get_registers_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -93,7 +90,7 @@ def test_get_registers(self): def test_get_locals(self): get_locals_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/get_locals', data=json.dumps(get_locals_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -101,7 +98,7 @@ def test_get_locals(self): def test_run_program(self): run_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/run', data=json.dumps(run_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -109,7 +106,7 @@ def test_run_program(self): def test_memory_map(self): memory_map_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/memory_map', data=json.dumps(memory_map_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -117,7 +114,7 @@ def test_memory_map(self): def test_continue_execution(self): continue_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/continue', data=json.dumps(continue_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -125,7 +122,7 @@ def test_continue_execution(self): def test_step_over(self): step_over_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/step_over', data=json.dumps(step_over_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -133,7 +130,7 @@ def test_step_over(self): def test_step_into(self): step_into_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/step_into', data=json.dumps(step_into_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -141,7 +138,7 @@ def test_step_into(self): def test_step_out(self): step_out_payload = { - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/step_out', data=json.dumps(step_out_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -150,7 +147,7 @@ def test_step_out(self): def test_add_watchpoint(self): add_watchpoint_payload = { "variable": "var", - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/add_watchpoint', data=json.dumps(add_watchpoint_payload), content_type='application/json') self.assertEqual(response.status_code, 200) @@ -159,13 +156,13 @@ def test_add_watchpoint(self): def test_delete_breakpoint(self): set_breakpoint_payload = { "location": "main", - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } self.client.post('/set_breakpoint', data=json.dumps(set_breakpoint_payload), content_type='application/json') delete_breakpoint_payload = { "breakpoint_number": 1, - "name": "test_program" + "name": f"{self.temp_dir.name}/test_program" } response = self.client.post('/delete_breakpoint', data=json.dumps(delete_breakpoint_payload), content_type='application/json') self.assertEqual(response.status_code, 200) From bf9b194152071b18c90515cde0f1324f4a987c10 Mon Sep 17 00:00:00 2001 From: Shubh942 <93862397+Shubh942@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:01:41 +0530 Subject: [PATCH 6/7] changes in yml file --- .github/workflows/run-test.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 19fee47..078401e 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -10,21 +10,17 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout target branch + - name: Checkout code uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.base.ref }} - - - name: Fetch pull request changes - run: | - git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge:pr - git checkout pr - name: Set up Python uses: actions/setup-python@v2 with: python-version: "3.10" + - name: Install gdb + run: sudo apt-get install -y gdb + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -32,4 +28,6 @@ jobs: - name: Run tests on changes run: | + git fetch origin ${{ github.event.pull_request.head.ref }} + git checkout FETCH_HEAD python -m unittest discover -s gdbui_server -p 'flask_test.py' From cdbbe36e403e3b45a5ff4cfd167ddb691632449a Mon Sep 17 00:00:00 2001 From: Shubh942 <93862397+Shubh942@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:03:49 +0530 Subject: [PATCH 7/7] changes in yml file --- .github/workflows/run-test.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 078401e..68f3164 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -10,8 +10,15 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Checkout target branch uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.base.ref }} + + - name: Fetch pull request changes + run: | + git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge:pr + git checkout pr - name: Set up Python uses: actions/setup-python@v2 @@ -28,6 +35,4 @@ jobs: - name: Run tests on changes run: | - git fetch origin ${{ github.event.pull_request.head.ref }} - git checkout FETCH_HEAD python -m unittest discover -s gdbui_server -p 'flask_test.py'