1

以下代码是非常样板代码,可以正常运行,但是在 gdb 中运行时会崩溃。因此,我不会在意,但这是我更大程序的简化版本,无论是否使用 gdb,它都会崩溃。对于我在这里做错的任何帮助将不胜感激。

它在最后一次调用 JVM “jobject hbase_configuration = env->CallStaticObjectMethod(cls, create_mid);”时崩溃

我已经尝试通过不同的东西通过 JNI 多次调用 HBaseConfiguration.Create ,并且在所有情况下它都会崩溃。gdb 上的堆栈跟踪似乎不是很有帮助,尽管使用 -g 编译,我无法从中获取任何符号。

#include <string>
#include <glog/logging.h>
#include <jni.h>
// (edit - this was hidden in the original post).

int main(int argc, char* argv[]) {
  JavaVM *jvm;
  JNIEnv *env;
  JavaVMInitArgs vm_args;
  JavaVMOption options[5];

  vm_args.nOptions = 5;
  vm_args.version = JNI_VERSION_1_6;
  vm_args.options = options;
  vm_args.ignoreUnrecognized = 1;


  JNI_GetDefaultJavaVMInitArgs(&vm_args);

  options[0].optionString = "-Djava.class.path=hbase-1.0-SNAPSHOT.jar:activation-1.1.jar:asm-3.1.jar:avro-1.7.1.cloudera.2.jar:commons-beanutils-1.7.0.jar:commons-beanutils-core-1.8.0.jar:commons-cli-1.2.jar:commons-codec-1.4.jar:commons-collections-3.2.1.jar:commons-configuration-1.6.jar:commons-daemon-1.0.3.jar:commons-digester-1.8.jar:commons-el-1.0.jar:commons-httpclient-3.1.jar:commons-io-2.1.jar:commons-lang-2.5.jar:commons-logging-1.1.1.jar:commons-math-2.1.jar:commons-net-3.1.jar:ftplet-api-1.0.0.jar:ftpserver-core-1.0.0.jar:ftpserver-deprecated-1.0.0-M2.jar:guava-11.0.2.jar:hadoop-annotations-2.0.0-cdh4.1.1.jar:hadoop-auth-2.0.0-cdh4.1.1.jar:hadoop-common-2.0.2-alpha.jar:hadoop-common-2.0.2-alpha-tests.jar:hadoop-hdfs-2.0.0-cdh4.1.1.jar:hadoop-test-2.0.0-mr1-cdh4.1.1.jar:hbase-0.92.1-cdh4.1.0.jar:hbase-0.92.1-cdh4.1.0-sources.jar:hbase-0.92.1-cdh4.1.0-tests.jar:high-scale-lib-1.1.1.jar:hsqldb-1.8.0.10.jar:jaxb-api-2.1.jar:jaxb-impl-2.2.3-1.jar:jersey-core-1.8.jar:jersey-json-1.8.jar:jersey-server-1.8.jar:jets3t-0.6.1.jar:jline-0.9.94.jar:jsch-0.1.42.jar:jsp-api-2.1.jar:jsr305-1.3.9.jar:junit-4.10.jar:kfs-0.3.jar:log4j-1.2.17.jar:metrics-core-2.1.2.jar:paranamer-2.3.jar:protobuf-java-2.4.1.jar:servlet-api-2.5.jar:tools.jar";
  options[1].optionString = "-verbose:jni";
  options[2].optionString = "-Xcheck:jni:pedantic,verbose";
  options[3].optionString = "-Xdebug";
  options[4].optionString = "-Xrunjdwp:transport=dt_socket,address=4242,server=y,suspend=n";
  vm_args.nOptions = 5;
  vm_args.version = JNI_VERSION_1_6;
  vm_args.options = options;
  vm_args.ignoreUnrecognized = 1;


  // Load and initialize a Java VM, return a JNI interface 
  // pointer in env.
  long result = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
  if (result == JNI_ERR) {
    LOG(ERROR) << "Failed to create a JVM";
    return false;
  }

   jclass cls = env->FindClass("org/apache/hadoop/hbase/HBaseConfiguration");
  if (cls == NULL) {
    LOG(ERROR) << " Could not find class org/apache/hadoop/hbase/HBaseConfiguration";
    return false;
  }

  jmethodID create_mid = env->GetStaticMethodID(
      cls, "create", "()Lorg/apache/hadoop/conf/Configuration;");
  if (create_mid == NULL) {
    LOG(ERROR) << "Could not find static method create in HBaseConfiguration";
    return false;
  }

  LOG(INFO) << "Creating conf";
  jobject hbase_configuration = env->CallStaticObjectMethod(cls, create_mid);

  LOG(INFO) << "Created conf";
  return 0;
}

堆栈跟踪如下所示:

#0  0x00007ffff134a722 in ?? ()
#1  0x00007ffff12e8410 in ?? ()
#2  0x0000000700000000 in ?? ()
#3  0x00007fffffffd150 in ?? ()
#4  0x00007fffffffd108 in ?? ()
#5  0x000000000060e800 in ?? ()
#6  0x000000077fbcaa30 in ?? ()
#7  0x000000000000001b in ?? ()
#8  0x0000000000000000 in ?? ()
4

1 回答 1

4

这确实是 technomage 在评论中所建议的。gdb 崩溃是一个红鲱鱼,因为 jvm 抛出了本来应该由 jvm 处理的 SIGSEGV。

一旦我告诉 gdb“处理 SIGSEGV nostop”,它就可以正常工作,并且我能够调试我的更大程序。

于 2012-11-16T15:19:11.650 回答