Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b3b5cf9
build(cmake): add App module sources to target
SizzleUnrlsd Jan 22, 2026
4adf3d7
fix(config): add standard headers and drop ipc dependency
SizzleUnrlsd Jan 22, 2026
53aa23a
fix(ipc): avoid unlinking socket path on client close
SizzleUnrlsd Jan 22, 2026
7fafb8a
fix(process): use per-run temp log file for UnixProcess
SizzleUnrlsd Jan 22, 2026
bc7e3d9
feat(output): add per-tool capture buffer and tool_out/tool_err
SizzleUnrlsd Jan 22, 2026
965f149
refactor(tools): route tool outputs through tool_out/tool_err
SizzleUnrlsd Jan 22, 2026
d8a88e3
fix(tools): include IpcStrategy definition
SizzleUnrlsd Jan 22, 2026
01cf832
refactor(tools): forward-declare IpcStrategy and add std includes
SizzleUnrlsd Jan 22, 2026
f909a27
feat(invoker): capture per-tool output and drop global mutex
SizzleUnrlsd Jan 22, 2026
f8cf925
feat(ipc): add serve to IPC_TYPES
SizzleUnrlsd Jan 22, 2026
abecde2
refactor(main): delegate to App config/runner modules
SizzleUnrlsd Jan 22, 2026
1db6cc4
refactor(stack-analyzer): emit tool output via tool_out
SizzleUnrlsd Jan 22, 2026
fef1cdb
refactor(tscancode): emit outputs via tool_out/tool_err
SizzleUnrlsd Jan 22, 2026
c8d9c31
build(cmake): add cpp-httplib FetchContent config
SizzleUnrlsd Jan 22, 2026
e1f3184
feat(ipc): add HTTP server for JSON API
SizzleUnrlsd Jan 22, 2026
6716db9
chore(app): add config module header
SizzleUnrlsd Jan 22, 2026
e2b8782
chore(app): add files module header
SizzleUnrlsd Jan 22, 2026
24b9a46
chore(app): add runner module header
SizzleUnrlsd Jan 22, 2026
a2c92a0
chore(attrs): add CT_NODISCARD macro header
SizzleUnrlsd Jan 22, 2026
3944f0a
feat(app): move CLI config parsing into App module
SizzleUnrlsd Jan 22, 2026
ba15ebb
feat(app): move source file resolution into App module
SizzleUnrlsd Jan 22, 2026
a37f003
chore(app): add runner module header
SizzleUnrlsd Jan 22, 2026
6a39975
docs(readme): update docs, examples and usage
SizzleUnrlsd Jan 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ set(COMMON_SOURCES
src/ArgumentParser/BaseArgumentParser.cpp
src/ArgumentParser/ArgumentManager.cpp
src/ArgumentParser/ArgumentParserFactory.cpp
src/App/Config.cpp
src/App/Files.cpp
src/App/Runner.cpp
src/ctrace_tools/mangle.cpp
src/ctrace_tools/languageType.cpp
src/ctrace_tools/strings.cpp
Expand Down Expand Up @@ -55,12 +58,19 @@ if (USE_ADDRESS_SANITIZER)
include(${CMAKE_SOURCE_DIR}/cmake/debug/sanitizer/AddressSanitizer.cmake)
endif()

# === INCLUDE .CMAKE ===

include(${CMAKE_SOURCE_DIR}/cmake/FetchNlohmannJson.cmake)
target_link_libraries(ctrace PRIVATE nlohmann_json::nlohmann_json)

include(${CMAKE_SOURCE_DIR}/cmake/stackUsageAnalyzer.cmake)
target_link_libraries(ctrace PRIVATE coretrace::stack_usage_analyzer_lib)

include(${CMAKE_SOURCE_DIR}/cmake/httpLib.cmake)
target_link_libraries(ctrace PRIVATE httplib::httplib)

# === OPTIONAL DEPENDENCIES ===

option(USE_EXTERNAL_CLI11 "Download CLI11" OFF)
if (USE_EXTERNAL_CLI11 AND PARSER_TYPE STREQUAL "CLI11")
include(${CMAKE_SOURCE_DIR}/cmake/CLI11.cmake)
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Options:
--invoke <tools> Invokes specific tools (comma-separated).
Available tools: flawfinder, ikos, cppcheck, tscancode.
--input <files> Specifies the source files to analyse (comma-separated).
--ipc <method> IPC method: standardIO, socket, or serve.
--ipc-path <path> IPC path (default: /tmp/coretrace_ipc).
--serve-host <host> HTTP server host when --ipc=serve.
--serve-port <port> HTTP server port when --ipc=serve.
--async Enables asynchronous execution.

Examples:
ctrace --input main.cpp,util.cpp --static --invoke=cppcheck,flawfinder
Expand All @@ -69,6 +74,46 @@ Description:
./ctrace --input ../tests/EmptyForStatement.cc --entry-points=main --verbose --static --dyn
```

### SERVER MODE

Start the HTTP server:

```bash
./ctrace --ipc serve --serve-host 127.0.0.1 --serve-port 8080
```

Send a request:

```bash
curl -X POST http://127.0.0.1:8080/api \
-H "Content-Type: application/json" \
-d '{
"proto": "coretrace-1.0",
"id": 1,
"type": "request",
"method": "run_analysis",
"params": {
"input": ["./tests/buffer_overflow.cc"],
"entry_points": ["main"],
"static_analysis": true,
"dynamic_analysis": false,
"invoke": ["flawfinder"],
"sarif_format": true,
"report_file": "ctrace-report.txt",
"output_file": "ctrace.out",
"ipc": "serve",
"ipc_path": "/tmp/coretrace_ipc",
"async": false,
"verbose": true
}
}'
```

Response notes:
- `status` is `ok` or `error`.
- `result.outputs` groups tool output by tool name.
- Each output entry has `stream` and `message`. If a tool emits JSON, `message` is returned as a JSON object.

### Mangle/Demangle API

```c++
Expand Down
9 changes: 9 additions & 0 deletions cmake/httpLib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(FetchContent)

FetchContent_Declare(
cpp_httplib
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
GIT_TAG v0.14.3
)

FetchContent_MakeAvailable(cpp_httplib)
12 changes: 12 additions & 0 deletions include/App/Config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef APP_CONFIG_HPP
#define APP_CONFIG_HPP

#include "Config/config.hpp"
#include "attributes.hpp"

namespace ctrace
{
CT_NODISCARD ProgramConfig buildConfig(int argc, char *argv[]);
}

#endif // APP_CONFIG_HPP
15 changes: 15 additions & 0 deletions include/App/Files.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef APP_FILES_HPP
#define APP_FILES_HPP

#include <string>
#include <vector>

#include "Config/config.hpp"
#include "attributes.hpp"

namespace ctrace
{
CT_NODISCARD std::vector<std::string> resolveSourceFiles(const ProgramConfig& config);
}

#endif // APP_FILES_HPP
13 changes: 13 additions & 0 deletions include/App/Runner.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef APP_RUNNER_HPP
#define APP_RUNNER_HPP

#include "Config/config.hpp"
#include "attributes.hpp"

namespace ctrace
{
CT_NODISCARD int run_server(const ProgramConfig& config);
CT_NODISCARD int run_cli_analysis(const ProgramConfig& config);
}

#endif // APP_RUNNER_HPP
25 changes: 21 additions & 4 deletions include/Config/config.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef CONFIG_HPP
#define CONFIG_HPP

#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <future>
Expand All @@ -9,7 +11,6 @@
#include "ArgumentParser/ArgumentManager.hpp"
#include "ArgumentParser/ArgumentParserFactory.hpp"
#include "ctrace_tools/strings.hpp"
#include "Process/Ipc/IpcStrategy.hpp"
#include "ctrace_defs/types.hpp"

static void printHelp(void)
Expand Down Expand Up @@ -79,6 +80,8 @@ namespace ctrace
bool hasInvokedSpecificTools = false; ///< Indicates if specific tools are invoked.
std::string ipc = ctrace_defs::IPC_TYPES.front(); ///< IPC method to use (e.g., fifo, socket).
std::string ipcPath = "/tmp/coretrace_ipc"; ///< Path for IPC communication.
std::string serverHost = "127.0.0.1"; ///< Host for server IPC (if applicable).
int serverPort = 8080; ///< Port for server IPC (if applicable).

std::vector<std::string> specificTools; ///< List of specific tools to invoke.

Expand Down Expand Up @@ -199,10 +202,14 @@ namespace ctrace
if (std::find(ipc_list.begin(), ipc_list.end(), value) == ipc_list.end())
{
std::cerr << "Invalid IPC type: '" << value << "'\n"
<< "Available IPC types: ";
<< "Available IPC types: [";
for (const auto& ipc : ipc_list)
std::cerr << ipc << " ";
std::cerr << std::endl;
{
std::cerr << ipc;
if (ipc != ipc_list.back())
std::cerr << ", ";
}
std::cerr << "]" << std::endl;
std::exit(EXIT_FAILURE);
}
config.global.ipc = value;
Expand All @@ -211,6 +218,16 @@ namespace ctrace
{
config.global.ipcPath = value;
};
commands["--serve-host"] = [this](const std::string& value)
{
config.global.serverHost = value;
std::cout << "[DEBUG] Server host set to " << config.global.serverHost << std::endl;
};
commands["--serve-port"] = [this](const std::string& value)
{
config.global.serverPort = std::stoi(value);
std::cout << "[DEBUG] Server port set to " << config.global.serverPort << std::endl;
};
// commands["--output"] = [this](const std::string& value) {
// if (!config.files.empty()) config.files.back().output_file = value;
// };
Expand Down
Loading
Loading