Skip to content
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

Update proguard and add remap_method fn #818

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Emit a MODULE record for PE files ([#814](https://github.com/getsentry/symbolic/pull/814))

**Features**

- Update proguard and add `remap_method` fn ([#818](https://github.com/getsentry/symbolic/pull/818))

## 12.4.1

**Fixes**
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions py/symbolic/proguard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
from typing import Tuple

import uuid as uuid_mod

Expand Down Expand Up @@ -55,6 +56,24 @@ def remap_class(self, klass: str) -> str | None:
)
return decode_str(klass, free=True) or None

def remap_method(self, klass: str, method: str) -> Tuple[str, str] | None:
"""Remaps the given class name."""
result = self._methodcall(
lib.symbolic_proguardmapper_remap_method,
encode_str(klass),
encode_str(method),
)

try:
output = (
decode_str(result.frames[0].class_name, free=False),
decode_str(result.frames[0].method, free=False),
)
finally:
rustcall(lib.symbolic_proguardmapper_result_free, ffi.addressof(result))

return output if len(output[0]) > 0 and len(output[1]) > 0 else None

def remap_frame(self, klass: str, method: str, line: int) -> list[JavaStackFrame]:
"""Remaps the stackframe, given its class, method and line."""
result = self._methodcall(
Expand Down
5 changes: 5 additions & 0 deletions py/tests/test_proguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def test_mapper(res_path):
== "android.support.constraint.ConstraintLayout$LayoutParams"
)

assert mapper.remap_method("android.support.constraint.a.b", "f") == (
"android.support.constraint.solver.ArrayRow",
"pickRowVariable",
)

remapped = mapper.remap_frame("android.support.constraint.a.b", "a", 116)
assert len(remapped) == 1
assert remapped[0].class_name == "android.support.constraint.solver.ArrayRow"
Expand Down
4 changes: 2 additions & 2 deletions symbolic-cabi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage = "https://github.com/getsentry/symbolic"
repository = "https://github.com/getsentry/symbolic"
description = """
C interface wrapper for symbolic, a library to symbolicate and process stack
traces from native applications, minidumps, minified JavaScripts or ProGuard
traces from native applications, minidumps, minified JavaScript or ProGuard
optimized Android apps.
"""
edition = "2021"
Expand All @@ -20,7 +20,7 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
proguard = { version = "5.0.2", features = ["uuid"] }
proguard = { version = "5.1.0", features = ["uuid"] }
sourcemap = "7.0.0"
symbolic = { version = "12.4.1", path = "../symbolic", features = ["cfi", "debuginfo", "sourcemapcache", "symcache"] }
tempfile = "3.4.0"
9 changes: 8 additions & 1 deletion symbolic-cabi/include/symbolic.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef SYMBOLIC_H_INCLUDED
#define SYMBOLIC_H_INCLUDED

/* Generated with cbindgen:0.24.3 */
/* Generated with cbindgen:0.24.5 */

/* Warning, this file is autogenerated. Do not modify this manually. */

Expand Down Expand Up @@ -520,6 +520,13 @@ struct SymbolicProguardRemapResult symbolic_proguardmapper_remap_frame(const str
struct SymbolicStr symbolic_proguardmapper_remap_class(const struct SymbolicProguardMapper *mapper,
const struct SymbolicStr *class_);

/**
* Remaps a class name.
*/
struct SymbolicProguardRemapResult symbolic_proguardmapper_remap_method(const struct SymbolicProguardMapper *mapper,
const struct SymbolicStr *class_,
const struct SymbolicStr *method);

/**
* Returns the UUID of a proguard mapping file.
*/
Expand Down
33 changes: 33 additions & 0 deletions symbolic-cabi/src/proguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@ ffi_fn! {
}
}

ffi_fn! {
/// Remaps a class name.
unsafe fn symbolic_proguardmapper_remap_method(
mapper: *const SymbolicProguardMapper,
class: *const SymbolicStr,
method: *const SymbolicStr,
) -> Result<SymbolicProguardRemapResult> {
let mapper = &SymbolicProguardMapper::as_rust(mapper).inner.get().mapper;

let class = (*class).as_str();
let method = (*method).as_str();

let (remapped_class, remapped_method) =
mapper.remap_method(class, method).unwrap_or_default();

let mut frames = vec![SymbolicJavaStackFrame {
class_name: remapped_class.to_owned().into(),
method: remapped_method.to_owned().into(),
file: "".to_owned().into(),
line: 0,
}];

frames.shrink_to_fit();
let rv = SymbolicProguardRemapResult {
frames: frames.as_mut_ptr(),
len: frames.len(),
};
std::mem::forget(frames);

Ok(rv)
}
}

ffi_fn! {
/// Returns the UUID of a proguard mapping file.
unsafe fn symbolic_proguardmapper_get_uuid(
Expand Down
3 changes: 1 addition & 2 deletions symbolic-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ repository = "https://github.com/getsentry/symbolic"
readme = "README.md"
description = """
Common types and utilities for symbolic, a library to symbolicate and process
stack traces from native applications, minidumps, minified JavaScripts or
ProGuard optimized Android apps.
stack traces from native applications, minidumps or minified JavaScript.
"""
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion symbolic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = "https://github.com/getsentry/symbolic"
readme = "README.md"
description = """
A library to symbolicate and process stack traces from native applications,
minidumps, Unreal Engine 4, minified JavaScripts or ProGuard optimized Android apps.
minidumps, Unreal Engine 4 or minified JavaScript.
"""
edition = "2021"

Expand Down
2 changes: 0 additions & 2 deletions symbolic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Symbolic provides the following functionality:
- Basic token mapping
- Heuristics to find original function names based on minified sources
- Indexed sourcemap to sourcemap merging
- Proguard function mappings
- Minidump / Breakpad processing
- Generate Breakpad symbol files from Mach, ELF and PDBs
- Process Minidumps to retrieve stack traces
Expand All @@ -48,7 +47,6 @@ of the features:
- **`minidump`**: Rust bindings for the Breakpad Minidump processor. Additionally, this includes
facilities to extract stack unwinding information (sometimes called CFI) from object files.
This feature requires a C++11 compiler on the PATH.
- **`proguard`**: Processing of Proguard mapping files to look up mangled Java function paths.
- **`sourcemap`**: Processing and expansion of JavaScript source maps, as well as lookups for
minified function names.
- **`symcache`**: An optimized, platform-independent storage for common debugging information.
Expand Down
2 changes: 1 addition & 1 deletion symbolic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! - Objective C / Objective C++
//! - Rust
//! - Swift
//! - JavaScript sourcemap expansion (vie `symbolic-cabi` only, use `sourcemap` crate instead)
//! - JavaScript sourcemap expansion (via `symbolic-cabi` only, use `sourcemap` crate instead)
//! - Proguard function mappings (via `symbolic-cabi` only, use `proguard` crate instead)
//! - Breakpad processing
//! - Generate Breakpad symbol files from Mach, ELF and PDBs
Expand Down
Loading