最近、私はC++の学習を始めました。私はObjective-Cでプログラミングすることに慣れているので、多分私はいくつかのことを間違っています。私はgdbセッションのトランスクリプトを作成しました:インスタンスをロードするときのcpp開発者のEXC_BAD_ACCESフォールト
Script started on Sat Jan 15 17:47:24 2011
bash-3.2$ gdb sscm
GNU gdb 6.3.50-20050815 (Apple version gdb-1510) (Wed Sep 22 02:45:02 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ... done
(gdb) break ServerOptions::ServerOptions
[0] cancel
[1] all
[2] ServerOptions::ServerOptions(int, char const**) at ServerOptions.cpp:33
[3] ServerOptions::ServerOptions(int, char const**) at ServerOptions.cpp:33
> 3
Breakpoint 1 at 0x7595: file ServerOptions.cpp, line 33.
(gdb) list
9
10 #include <iostream>
11
12 #include "Logger.h"
13 #include "ServerOptions.h"
14
15
16 int main(int argc, const char **argv) {
17 using namespace std;
18 ServerOptions options(argc, argv);
(gdb) run
Starting program: /Users/ief2/Desktop/SSCM-1.0.0.9/server/sscmd
Reading symbols for shared libraries ++. done
Breakpoint 1, ServerOptions::ServerOptions (this=0xbffff7a8, argc=1, argv=0xbffff7f0) at ServerOptions.cpp:33
33 ServerOptions::ServerOptions(int argc, const char **argv)
(gdb) s
36 bool noErrorsEncountered = true;
(gdb) list
31 is a fatal error.
32 */
33 ServerOptions::ServerOptions(int argc, const char **argv)
34 {
35 /* setup default values */
36 bool noErrorsEncountered = true;
37 int isDaemon = true;
38 int displayHelp = false;
39 int port = DEFAULT_BIND_PORT;
40 std::string rootFolder = "";
(gdb) s
37 int isDaemon = true;
(gdb) s
38 int displayHelp = false;
(gdb) s
39 int port = DEFAULT_BIND_PORT;
(gdb)
40 std::string rootFolder = "";
(gdb) list
35 /* setup default values */
36 bool noErrorsEncountered = true;
37 int isDaemon = true;
38 int displayHelp = false;
39 int port = DEFAULT_BIND_PORT;
40 std::string rootFolder = "";
41 int isSilent = 0;
42
43 Logger logger = Logger::sharedLogger();
44
(gdb)
45 /* Process the configuration file */
46 {
47 int status;
48 std::string anArgument;
49 KeyFile file(DEFAULT_CONFIGURATION_FILE,
50 &status);
51
52 if(status != 0 && status != ENOENT) {
53 std::stringstream strstr;
54 strstr <<
(gdb) lists[Klists[K
41 int isSilent = 0;
(gdb)
43 Logger logger = Logger::sharedLogger();
(gdb)
Logger::sharedLogger() at Logger.cpp:28
28 if(logger == NULL) {
(gdb) list
23 }
24
25 Logger& Logger::sharedLogger(void) {
26 static Logger *logger = NULL;
27
28 if(logger == NULL) {
29 new Logger("");
30 }
31
32 return *logger;
(gdb) s
29 new Logger("");
(gdb)
Logger::Logger (this=0x100160, [email protected]) at Logger.cpp:16
16 Logger::Logger(std::string fullPath) {
(gdb) list
11
12 #pragma mark -
13 #pragma mark Public Implementation
14
15 #pragma mark Constructors and Destructors
16 Logger::Logger(std::string fullPath) {
17 _filename = fullPath;
18 _isSilent = false;
19 }
20
(gdb) s
17 _filename = fullPath;
(gdb)
18 _isSilent = false;
(gdb)
19 }
(gdb)
Logger::sharedLogger() at Logger.cpp:32
32 return *logger;
(gdb)
33 }
(gdb)
Logger::Logger (this=0xbffff6ec) at Logger.h:21
21 class Logger {
(gdb) llist ist
16 #include <cerrno>
17 #include <cstring>
18
19 #pragma mark -
20 #pragma mark Private Interface
21 class Logger {
22 private:
23 std::string _filename;
24 bool _isSilent;
25
(gdb)
26 public:
27 #pragma mark Constructors and Destructors
28 Logger(std::string fullPath);
29 ~Logger(void);
30 static Logger& sharedLogger(void);
31
32 #pragma mark Getters and Setters
33 std::string getFilename(void) const;
34 void setFilename(std::string newF);
35
(gdb) s
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x980f7b33 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()
(gdb) ki
Kill the program being debugged? (y or n) y
(gdb) q
bash-3.2$ exit
exit
Script done on Sat Jan 15 17:48:59 2011
なぜこのエラーが発生しているのですか?より多くのコードが必要な場合は、私は確かにそれを投稿します!
あなたはライン29上のライン32上のNULL
ポインタを参照解除され、事前にIEF2
あなたが取得していますNULLポインタ例外。例外が発生している場所では、有効なオブジェクトを指すポインターなしでクラスメンバーにアクセスしようとしています。 – Jaywalker