Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit b76bd59

Browse files
jasonborgcopybara-github
authored andcommitted
Support collecting debuggee label from yaml config reader.
PiperOrigin-RevId: 371699766 Change-Id: I6ce10af3b72ed513918fd781da358acf06d87cd1
1 parent ec02d28 commit b76bd59

File tree

7 files changed

+100
-22
lines changed

7 files changed

+100
-22
lines changed

src/agent/debuggee_labels.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "debuggee_labels.h"
2+
3+
namespace devtools {
4+
namespace cdbg {
5+
6+
constexpr char DebuggeeLabels::kBlocklistSourceLabel[];
7+
constexpr char DebuggeeLabels::kBlocklistSourceDeprecatedFile[];
8+
constexpr char DebuggeeLabels::kBlocklistSourceFile[];
9+
constexpr char DebuggeeLabels::kBlocklistSourceNone[];
10+
11+
void DebuggeeLabels::Set(const std::string& /* name */,
12+
const std::string& /* value */) {
13+
// TODO: Implement in follow on CL.
14+
}
15+
16+
} // namespace cdbg
17+
} // namespace devtools

src/agent/debuggee_labels.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef DEVTOOLS_CDBG_DEBUGLETS_JAVA_DEBUGGEE_LABELS_H_
2+
#define DEVTOOLS_CDBG_DEBUGLETS_JAVA_DEBUGGEE_LABELS_H_
3+
4+
#include <map>
5+
6+
#include "jni_proxy_ju_hashmap.h"
7+
8+
namespace devtools {
9+
namespace cdbg {
10+
11+
// Utility class to hold labels to include in the registerDebuggee call that
12+
// goes to the HubClient on the Java side of the agent. This class will hold the
13+
// labels and then will handle generating the Java HashMap that can use used in
14+
// the registerDebuggee call.
15+
class DebuggeeLabels {
16+
public:
17+
DebuggeeLabels() = default;
18+
19+
static constexpr char kBlocklistSourceLabel[] = "blocklistsource";
20+
21+
// Value for the BlocklistSource label which indicates the deprecated file
22+
// name and format was used for specifying the blocklist.
23+
static constexpr char kBlocklistSourceDeprecatedFile[] = "deprecatedfile";
24+
25+
// Value for the BlocklistSource label which indicates the new blocklist file
26+
// name and format was used for specifying the blocklist.
27+
static constexpr char kBlocklistSourceFile[] = "file";
28+
29+
// Value for the BlocklistSource label which indicates no blocklist was
30+
// specfified.
31+
static constexpr char kBlocklistSourceNone[] = "none";
32+
33+
void Set(const std::string& name, const std::string& value);
34+
};
35+
36+
} // namespace cdbg
37+
} // namespace devtools
38+
39+
#endif // DEVTOOLS_CDBG_DEBUGLETS_JAVA_DEBUGGEE_LABELS_H_

src/agent/jvmti_agent.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ JvmtiAgent::JvmtiAgent(
9999
std::unique_ptr<Bridge> bridge,
100100
std::function<JniLocalRef()> breakpoint_labels_provider_factory,
101101
std::function<JniLocalRef()> user_id_provider_factory,
102-
std::function<std::unique_ptr<DataVisibilityPolicy>(ClassPathLookup*)>
102+
std::function<std::unique_ptr<DataVisibilityPolicy>(ClassPathLookup*,
103+
DebuggeeLabels*)>
103104
data_visibility_policy_fn,
104105
bool enable_capabilities,
105106
bool enable_jvmti_events)
@@ -380,8 +381,13 @@ bool JvmtiAgent::OnWorkerReady() {
380381
return false;
381382
}
382383

384+
// TODO The labels will be wired up and passed out in a follow on
385+
// CL.
386+
DebuggeeLabels debuggee_labels;
387+
383388
// Load data visibility configuration.
384-
data_visibility_policy_ = data_visibility_policy_fn_(internals_);
389+
data_visibility_policy_ =
390+
data_visibility_policy_fn_(internals_, &debuggee_labels);
385391

386392
return true;
387393
}

src/agent/jvmti_agent.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "common.h"
2525
#include "config.h"
2626
#include "data_visibility_policy.h"
27+
#include "debuggee_labels.h"
2728
#include "debugger.h"
2829
#include "eval_call_stack.h"
2930
#include "jvm_internals.h"
@@ -57,7 +58,8 @@ class JvmtiAgent : public Worker::Provider {
5758
std::unique_ptr<Bridge> bridge,
5859
std::function<JniLocalRef()> breakpoint_labels_provider_factory,
5960
std::function<JniLocalRef()> user_id_provider_factory,
60-
std::function<std::unique_ptr<DataVisibilityPolicy>(ClassPathLookup*)>
61+
std::function<std::unique_ptr<DataVisibilityPolicy>(ClassPathLookup*,
62+
DebuggeeLabels*)>
6163
data_visibility_policy_fn,
6264
bool enable_capabilities,
6365
bool enable_jvmti_events);
@@ -167,7 +169,8 @@ class JvmtiAgent : public Worker::Provider {
167169
const std::function<JniLocalRef()> user_id_provider_factory_;
168170

169171
// Reads data visibility configuration from .JAR files.
170-
const std::function<std::unique_ptr<DataVisibilityPolicy>(ClassPathLookup*)>
172+
const std::function<std::unique_ptr<DataVisibilityPolicy>(ClassPathLookup*,
173+
DebuggeeLabels*)>
171174
data_visibility_policy_fn_;
172175

173176
// When false, don't enable JVMTI capabilities.

src/agent/jvmti_globals.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "callbacks_monitor.h"
2424
#include "common.h"
25+
#include "debuggee_labels.h"
2526
#include "jvm_eval_call_stack.h"
2627
#include "jvm_internals.h"
2728
#include "jvmti_buffer.h"
@@ -383,10 +384,15 @@ Agent_OnLoad(JavaVM* vm, char* options, void* reserved) {
383384
// There is no user id provider in GCE environment.
384385
return nullptr;
385386
},
386-
[glob_policy] (devtools::cdbg::ClassPathLookup* class_path_lookup) {
387+
[glob_policy](devtools::cdbg::ClassPathLookup* class_path_lookup,
388+
devtools::cdbg::DebuggeeLabels* debuggee_labels) {
389+
std::string yaml_config_source;
387390
glob_policy->SetConfig(
388391
devtools::cdbg::ReadYamlDataVisibilityConfiguration(
389-
class_path_lookup));
392+
class_path_lookup, &yaml_config_source));
393+
debuggee_labels->Set(
394+
devtools::cdbg::DebuggeeLabels::kBlocklistSourceLabel,
395+
yaml_config_source);
390396
return std::unique_ptr<devtools::cdbg::DataVisibilityPolicy>(
391397
glob_policy);
392398
},

src/agent/yaml_data_visibility_config_reader.cc

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "yaml_data_visibility_config_reader.h"
22

3+
#include "debuggee_labels.h"
34
#include "jni_proxy_yamlconfigparser.h"
45
#include "jni_utils.h"
56

@@ -18,11 +19,17 @@ static constexpr char kResourcePathDeprecated[] = "debugger-blacklist.yaml";
1819
// - No config file is found. Sets config to ""
1920
// Returns false (error) if there were multiple configurations found.
2021
static bool ReadYamlConfig(ClassPathLookup* class_path_lookup,
21-
std::string* config_file_name, std::string* config,
22+
std::string* config_file_name,
23+
std::string* blocklist_source, std::string* config,
2224
std::string* error) {
2325
std::set<std::string> files =
2426
class_path_lookup->ReadApplicationResource(kResourcePath);
2527

28+
if (!files.empty()) {
29+
*config_file_name = kResourcePath;
30+
*blocklist_source = DebuggeeLabels::kBlocklistSourceFile;
31+
}
32+
2633
if (files.size() > 1) {
2734
LOG(ERROR) << "Multiple " << kResourcePath << " files found."
2835
<< " Found " << files.size() << " files.";
@@ -33,13 +40,18 @@ static bool ReadYamlConfig(ClassPathLookup* class_path_lookup,
3340
return false;
3441
}
3542

36-
if (files.size() == 1) {
37-
*config_file_name = kResourcePath;
38-
} else {
39-
// TODO: Finalize the conversion to blocklist, this else block
40-
// can be removed.
43+
// TODO: Finalize the conversion to blocklist, this block can be
44+
// removed.
45+
if (files.empty()) {
4146
files = class_path_lookup->ReadApplicationResource(kResourcePathDeprecated);
4247

48+
if (!files.empty()) {
49+
*config_file_name = kResourcePathDeprecated;
50+
*blocklist_source = DebuggeeLabels::kBlocklistSourceDeprecatedFile;
51+
LOG(WARNING) << "The use of debugger-blacklist.yaml has been deprecated, "
52+
"please use debugger-blocklist instead";
53+
}
54+
4355
if (files.size() > 1) {
4456
LOG(ERROR) << "Multiple " << kResourcePathDeprecated << " files found."
4557
<< " Found " << files.size() << " files.";
@@ -48,18 +60,13 @@ static bool ReadYamlConfig(ClassPathLookup* class_path_lookup,
4860
"Please contact your system administrator.";
4961
return false;
5062
}
51-
52-
if (files.size() == 1) {
53-
*config_file_name = kResourcePathDeprecated;
54-
LOG(WARNING) << "The use of debugger-blacklist.yaml has been deprecated, "
55-
"please use debugger-blocklist instead";
56-
}
5763
}
5864

5965
if (files.empty()) {
6066
// No configuration file was provided
6167
LOG(INFO) << kResourcePath << " was not found. Using default settings.";
6268
*config = "";
69+
*blocklist_source = DebuggeeLabels::kBlocklistSourceNone;
6370
} else {
6471
*config = *files.begin();
6572
}
@@ -136,14 +143,14 @@ static bool ParseYamlConfig(const std::string& yaml_config,
136143
}
137144

138145
GlobDataVisibilityPolicy::Config ReadYamlDataVisibilityConfiguration(
139-
ClassPathLookup* class_path_lookup) {
146+
ClassPathLookup* class_path_lookup, std::string* blocklist_source) {
140147
GlobDataVisibilityPolicy::Config config;
141148

142149
std::string yaml_config;
143150
std::string config_file_name;
144151
std::string error;
145-
if (!ReadYamlConfig(class_path_lookup, &config_file_name, &yaml_config,
146-
&error)) {
152+
if (!ReadYamlConfig(class_path_lookup, &config_file_name,
153+
blocklist_source, &yaml_config, &error)) {
147154
config.parse_error = error;
148155
return config;
149156
}

src/agent/yaml_data_visibility_config_reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace cdbg {
1010

1111
// Loads .yaml visibility configuration.
1212
GlobDataVisibilityPolicy::Config ReadYamlDataVisibilityConfiguration(
13-
ClassPathLookup* class_path_lookup);
13+
ClassPathLookup* class_path_lookup, std::string* yaml_source);
1414

1515
} // namespace cdbg
1616
} // namespace devtools

0 commit comments

Comments
 (0)