Skip to content

Common casr tool #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft

Common casr tool #259

wants to merge 25 commits into from

Conversation

hkctkuy
Copy link
Member

@hkctkuy hkctkuy commented May 10, 2025

Nobody wanted it, nobody asked it, but we did it anyway.

@hkctkuy hkctkuy requested a review from SweetVishnya May 10, 2025 15:15
@hkctkuy hkctkuy marked this pull request as draft May 10, 2025 15:16
Copy link

codecov bot commented May 10, 2025

Codecov Report

Attention: Patch coverage is 81.25561% with 209 lines in your changes missing coverage. Please review.

Project coverage is 64.47%. Comparing base (4bc482c) to head (1a92ab2).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
casr/src/common.rs 77.09% 82 Missing ⚠️
libcasr/src/go.rs 13.33% 26 Missing ⚠️
libcasr/src/rust.rs 13.33% 26 Missing ⚠️
casr/src/stub.rs 0.00% 19 Missing ⚠️
casr/src/run.rs 87.61% 13 Missing ⚠️
libcasr/src/asan.rs 86.30% 10 Missing ⚠️
libcasr/src/python.rs 85.00% 9 Missing ⚠️
libcasr/src/msan.rs 87.50% 5 Missing ⚠️
casr/src/bin/casr.rs 97.43% 4 Missing ⚠️
libcasr/src/java.rs 92.10% 3 Missing ⚠️
... and 11 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #259      +/-   ##
==========================================
- Coverage   66.64%   64.47%   -2.17%     
==========================================
  Files          34       39       +5     
  Lines        8266     7629     -637     
==========================================
- Hits         5509     4919     -590     
+ Misses       2757     2710      -47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

let output = Command::new(EXE_CASR_SAN)
.args(["--stdout", "--", &paths[1]])
let output = Command::new(EXE_CASR)
.args(["asan", "--stdout", "--", &paths[1]])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR, casr-san handles all sanitizers (e.g., msan). Maybe, we should rename casr asan to casr san?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is san mod for backward capability with bahaviour that is equal to casr-san, asan and msan modes are needed for explicit indication for the parser when we are confident in it and do not want to try to guess it. The equal case for go and rust

@@ -0,0 +1,121 @@
//! Gdb module implements `ParseStacktrace`, `Exception` and `Severity` traits for Gdb output.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These docs should be updated, I suppose

maps: Vec<String>,
report: Vec<String>,
stream: String,
stacktrace: Option<Stacktrace>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add docs to all fields

};
use regex::Regex;
/// Structure provides an interface for save parsing gdb crash.
pub struct GdbCrash {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd better call it GdbCrashReport or GdbCrashInfo

return Err(Error::Casr("Unable to get results from gdb".to_string()));
};
let stream = String::from_utf8_lossy(&stream);
let stream = stream.to_string();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually need this to_string?

}
/// Get disassembly
pub fn disassembly(&self) -> &str {
&self.report[5]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add it to GdbContext? I'm not sure by the way...

Copy link
Member Author

@hkctkuy hkctkuy May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does a lib user know, that the disassmebly is inside someRandomField[someRandomNumber]?

/// Structure provides an interface for save parsing some sanitizer crash.
#[derive(Clone, Debug)]
pub struct SanCrash {
context: StacktraceContext,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a duplicate of StacktraceContext, do we need a new structure here? Or we can just create an alias?


impl AsanCrash {
/// Create new `AsanCrash` instance from stream
pub fn new(stream: &str) -> Result<Option<Self>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, we need some library tests for newly added functions.

@@ -116,7 +120,24 @@ impl ParseStacktrace for CSharpStacktrace {
}

/// Structure provides an interface for parsing c# exception message.
pub struct CSharpException;
pub struct CSharpException {
context: StacktraceContext,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here, mostly looks like a duplicate structure

@@ -20,7 +22,7 @@ impl ParseStacktrace for JavaStacktrace {
conv_counter: usize,
}
// Get java stack trace.
let re = Regex::new(r"(?m)^(?:Caused by:|Exception in thread|== Java Exception:)(?:.|\n)*?((?:\n\s+at .*\(.*\))+)(?:\n\s+\.\.\. (\d+) more)?").unwrap();
let re = Regex::new(r"(?m)^(?:Caused by:|Exception in thread|== Java Exception:)(?:.|\n)*?((?:\n\s*at .*\(.*\))+)(?:\n\s*\.\.\. (\d+) more)?").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we upstream first this change in a separate PR?


impl PythonException {
/// Create new `PythonException` instance from Python output
fn new_from_python(stream: &str) -> Result<Option<Self>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can just call it from_python

let sub = matches.subcommand();
for arg in args {
if !matches.contains_id(arg) && (sub.is_none() || !sub.unwrap().1.contains_id(arg)) {
bail!("The following argument is required: {}", arg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same message as clap throws?

casr_cmd.envs(&self.envs);

// Add envs
if self.target_args.iter().any(|x| x.eq("-detect_leaks=0")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we remove this code?

Copy link
Member Author

@hkctkuy hkctkuy May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dоn't, just move it to the upper function

impl fmt::Display for Mode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Mode::Csharp => "csharp",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can store string mapping for enum somewhere, so, we don't repeate the same string constants

This function is a reverse function of new()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more optimal way then searching in map

use goblin::container::Endian;
use goblin::elf::{Elf, header};

pub fn gdb_run(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, some of the code here can be moved to libcasr

Ok(())
}

pub fn prepare_run(argv: &mut [String], mode: &Mode) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reduce copy-paste here? So, adding new cast tools could be easier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants