Skip to content

Commit f771080

Browse files
committed
Ported trace-module to module-sdk platform
0 parents  commit f771080

File tree

11 files changed

+341
-0
lines changed

11 files changed

+341
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea
2+
/out
3+
/cmake-build-debug

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
project(trace_module)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
6+
add_executable(trace_module
7+
src/module.cc
8+
src/module.h
9+
src/instrumentation_pass.cc
10+
src/instrumentation_pass.h
11+
src/codelib.cc
12+
src/codelib.h)
13+
14+
target_include_directories(trace_module PUBLIC
15+
/opt/artist-sdk/include/external/valgrind
16+
/opt/artist-sdk/include/external/valgrind/include
17+
/opt/artist-sdk/include/bionic/libc/private
18+
/opt/artist-sdk/include/art/runtime
19+
/opt/artist-sdk/include/art/compiler
20+
/opt/artist-sdk/include/art/compiler/optimizing
21+
/opt/artist-sdk/include/libnativehelper/include/nativehelper
22+
/opt/artist-sdk/include/external/libcxx/include
23+
/opt/artist-sdk/include/bionic/libc/arch-arm/include
24+
/opt/artist-sdk/include/bionic/libc/include
25+
/opt/artist-sdk/include/bionic/libc/kernel/uapi
26+
/opt/artist-sdk/include/bionic/libc/kernel/uapi/asm-arm
27+
/opt/artist-sdk/include/bionic/libm/include)

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ARTIST_SDK ?= /opt/artist-sdk
2+
3+
include $(ARTIST_SDK)/makefiles/core.mk

Manifest.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"manifest_version": 1,
3+
"package_name": "saarland.cispa.artist.module.trace",
4+
"name": "Trace Module",
5+
"description": "This module logs all called methods.",
6+
"author": "Sebastian Weisgerber <[email protected]>, Oliver Schranz <[email protected]>, Parthipan Ramesh <[email protected]>",
7+
"version": 1
8+
}

codelib.apk

4.87 KB
Binary file not shown.

src/codelib.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* The ARTist Project (https://artist.cispa.saarland)
3+
*
4+
* Copyright (C) 2017 CISPA (https://cispa.saarland), Saarland University
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author "Oliver Schranz <[email protected]>"
19+
* @author "Sebastian Weisgerber <[email protected]>"
20+
*
21+
*/
22+
23+
#include "codelib.h"
24+
25+
const std::string TraceCodeLib::TRACELOG("Lsaarland/cispa/artist/codelib/CodeLib;traceLog()V");
26+
27+
unordered_set<string>& TraceCodeLib::getMethods() const {
28+
static unordered_set<string> methods({TRACELOG});
29+
return methods;
30+
}
31+
string& TraceCodeLib::getInstanceField() const {
32+
static string instanceField = "Lsaarland/cispa/artist/codelib/CodeLib;INSTANCE";
33+
return instanceField;
34+
}
35+
string& TraceCodeLib::getCodeClass() const {
36+
static string codeClass = "Lsaarland/cispa/artist/codelib/CodeLib;";
37+
return codeClass;
38+
}

src/codelib.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* The ARTist Project (https://artist.cispa.saarland)
3+
*
4+
* Copyright (C) 2017 CISPA (https://cispa.saarland), Saarland University
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author "Oliver Schranz <[email protected]>"
19+
* @author "Sebastian Weisgerber <[email protected]>"
20+
*
21+
*/
22+
23+
#ifndef ART_MODULES_TRACE_TRACE_CODELIB_H_
24+
#define ART_MODULES_TRACE_TRACE_CODELIB_H_
25+
26+
#include <string>
27+
#include <unordered_set>
28+
#include <artist/env/codelib.h>
29+
30+
using std::string;
31+
using std::unordered_set;
32+
33+
using art::CodeLib;
34+
35+
class TraceCodeLib : public CodeLib {
36+
public:
37+
static const string TRACELOG;
38+
39+
public:
40+
TraceCodeLib() = default;
41+
TraceCodeLib(const TraceCodeLib& other) = default;
42+
TraceCodeLib(TraceCodeLib&& other) = default;
43+
44+
~TraceCodeLib() override = default;
45+
46+
TraceCodeLib& operator=(const TraceCodeLib&) = default;
47+
TraceCodeLib& operator=(TraceCodeLib&&) = default;
48+
49+
unordered_set<string>& getMethods() const override;
50+
string& getInstanceField() const override;
51+
string& getCodeClass() const override;
52+
}; // class TraceCodeLib
53+
54+
#endif // ART_MODULES_TRACE_TRACE_CODELIB_H_

src/instrumentation_pass.cc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* The ARTist Project (https://artist.cispa.saarland)
3+
*
4+
* Copyright (C) 2017 CISPA (https://cispa.saarland), Saarland University
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author "Oliver Schranz <[email protected]>"
19+
* @author "Sebastian Weisgerber <[email protected]>"
20+
*
21+
*/
22+
23+
#include <atomic>
24+
25+
#include <artist/artist_log.h>
26+
#include <artist/injection/injection_visitor.h>
27+
#include <artist/env/java_env.h>
28+
#include <artist/injection/primitives.h>
29+
#include <artist/injection/boolean.h>
30+
#include <artist/injection/integer.h>
31+
#include <artist/injection/float.h>
32+
#include <artist/verbose_printer.h>
33+
#include <artist/injection/char.h>
34+
35+
#include "instrumentation_pass.h"
36+
#include "codelib.h"
37+
38+
using std::string;
39+
using std::vector;
40+
using std::shared_ptr;
41+
using std::make_shared;
42+
using std::endl;
43+
using std::sort;
44+
45+
using art::Target;
46+
using art::Parameter;
47+
using art::Char;
48+
using art::InjectionTarget ;
49+
50+
vector<Injection> HTraceArtist::ProvideInjections() const {
51+
vector<shared_ptr<const Parameter>> params;
52+
auto param = make_shared<const Char>();
53+
params.push_back(param);
54+
55+
vector<const Target> targets;
56+
const Target target(Target::GENERIC_TARGET, InjectionTarget::METHOD_END);
57+
targets.push_back(target);
58+
59+
Injection injection(TraceCodeLib::TRACELOG, params, targets);
60+
61+
vector<Injection> results;
62+
results.push_back(injection);
63+
return results;
64+
}

src/instrumentation_pass.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* The ARTist Project (https://artist.cispa.saarland)
3+
*
4+
* Copyright (C) 2017 CISPA (https://cispa.saarland), Saarland University
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author "Oliver Schranz <[email protected]>"
19+
* @author "Sebastian Weisgerber <[email protected]>"
20+
*
21+
*/
22+
23+
#ifndef ART_MODULES_TRACE_TRACE_ARTIST_H_
24+
#define ART_MODULES_TRACE_TRACE_ARTIST_H_
25+
26+
#include <artist/injection/universal_artist.h>
27+
28+
using art::HUniversalArtist;
29+
using art::MethodInfo;
30+
using art::OptimizingCompilerStats;
31+
using art::Injection;
32+
33+
class HTraceArtist : public HUniversalArtist {
34+
public:
35+
explicit HTraceArtist(
36+
const MethodInfo& method_info,
37+
#ifdef BUILD_MARSHMALLOW
38+
bool is_in_ssa_form = true,
39+
#endif
40+
const char* pass_name = "TraceArtist"
41+
, OptimizingCompilerStats* stats = nullptr)
42+
: HUniversalArtist(method_info
43+
#ifdef BUILD_MARSHMALLOW
44+
, is_in_ssa_form
45+
#endif
46+
, pass_name
47+
, stats) {
48+
// Nothing
49+
}
50+
51+
vector<Injection> ProvideInjections() const OVERRIDE;
52+
};
53+
54+
#endif // ART_MODULES_TRACE_TRACE_ARTIST_H_

src/module.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* The ARTist Project (https://artist.cispa.saarland)
3+
*
4+
* Copyright (C) 2017 CISPA (https://cispa.saarland), Saarland University
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author "Oliver Schranz <[email protected]>"
19+
*
20+
*/
21+
22+
#include <artist/filtering/method_name_filters.h>
23+
24+
#include "module.h"
25+
#include "instrumentation_pass.h"
26+
#include "codelib.h"
27+
28+
using std::make_shared;
29+
using std::unique_ptr;
30+
31+
shared_ptr <HArtist> TraceModule::createPass(const MethodInfo &method_info) const {
32+
return make_shared<HTraceArtist>(method_info);
33+
}
34+
35+
shared_ptr<const CodeLib> TraceModule::createCodeLib() const {
36+
return make_shared<TraceCodeLib>();
37+
}
38+
39+
// skip android support lib ui methods since they bloat up the log
40+
unique_ptr <Filter> TraceModule::getMethodFilter() const {
41+
const vector<const string> ui = {"android.support."};
42+
return unique_ptr<Filter>(new art::BlacklistFilter(ui));
43+
}
44+
45+
// the class factories
46+
47+
extern "C" shared_ptr <art::Module> create() {
48+
return make_shared<TraceModule>();
49+
}

0 commit comments

Comments
 (0)