1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_DEBUGD_MAIN
38 #include"drd64_debugd.h"
41 void Drd64_Debugd_SigTerm( siginfo_t *info, ucontext_t *uap)
43 Drd64_Debugd_Debug_Detach( &drd64_debugd_info );
45 free( gp_sendbuffer );
47 close( drd64_debugd_info.i_socket_debugd );
48 close( drd64_debugd_info.i_socket_client );
50 DRD64_LOG_INFO("[INFO] Terminate drdebugd. Good-Bye.");
51 Drd64_Server_Log_TermLogSystem();
57 void Drd64_Debugd_SigHup( siginfo_t *info, ucontext_t *uap)
64 Drd64_Debugd_Main_PreInit(
65 Drd64_Debugd_MasterInformation *p_debugd )
67 Drd64_Server_Log_InitLogSystem(
68 DRD64_LOG_MODULE_DEBUGD,
69 DRD64_LOG_LEVEL_DEBUGD,
70 DRD64_LOG_FACILITY_DEBUGD );
72 DRD64_LOG_INFO("**************************************************");
73 DRD64_LOG_INFO("drd64_debugd : Dr.Deamon64 Process Debugger Deamon");
74 DRD64_LOG_INFO("Copyright(C) 2007- Koine Yuusuke(koinec). All rights reserved.");
75 DRD64_LOG_INFO("[Arch]: INTEL64(amd64/x86-64) / FreeBSD");
76 DRD64_LOG_INFO("[INFO]: Booting drdebugd");
83 Drd64_Debugd_Main_Init(
84 Drd64_Debugd_MasterInformation *p_debugd,
89 /* Set Signal Functions */
90 Drd64_Server_Common_Signal( SIGINT, Drd64_Debugd_SigTerm );
91 Drd64_Server_Common_Signal( SIGTERM, Drd64_Debugd_SigTerm );
92 Drd64_Server_Common_Signal( SIGHUP, Drd64_Debugd_SigHup );
94 /* Init Recv.Status Struct */
95 i_err = Drd64_Server_RecvStatus_Init( DRD64_DEBUGD_RECVSTATUS_UNITS );
96 if( 0x00 != i_err ) { return i_err; }
98 /* Init Packet Read Buffer */
99 Drd64_Server_RecvSocket_InitReadBuffer();
101 /* Create Socket from Local Client or Marshald */
102 /* GOMI : Drd64_Server_Socket_InitSocket_Local( p_debugd->str_socketname ); */
103 p_debugd->i_socket_debugd =
104 Drd64_LibBrownie_Socket_InitSocketServer_Local(
105 p_debugd->str_socketname );
106 if( 0 > p_debugd->i_socket_debugd ) {
110 /* Init Packet Data Buffer for Send */
111 gp_sendbuffer = (Byte *)malloc( DRD64_MAX_PACKET_LENGTH );
112 if( NULL == gp_sendbuffer ) { return 0x03; }
114 /* Attach or Debug-Start */
116 /* Send Debugd-Boot-Info. Packet to Local-Marshald */
117 i_err = Drd64_Debugd_Send_Cmd_BootInfo( i_request_fd );
118 if( 0x00 != i_err ) { return i_err; }
125 Drd64_Debugd_Main_Usage(
128 puts("drd64_debugd : Dr.Deamon64 Process Debugger Deamon");
129 puts("Copyright(C) 2007- Koine Yuusuke(koinec). All rights reserved.");
130 puts("[Arch]: INTEL64(amd64/x86-64) / FreeBSD");
131 puts(" ** CAUTION! ** ");
132 puts(" This Program have Booted by drd64_marshald.");
133 puts(" So, You can't boot drd64_debugd by Command-Line.");
140 Drd64_Debugd_Main_AnalyzeOption(
141 Drd64_Debugd_MasterInformation *p_debugd,
158 while( -1 != ( i_opt = getopt( argc, argv, "n:c:r:m:a:d" )) ) {
159 if( 1 < i_flag_debug )
162 /* "n" : SocketName for Client */
164 strncpy( p_debugd->str_socketname, optarg, DRD64_MAX_PATH );
167 /* "c" : coredump File Name */
168 else if( 'c' == i_opt ) {
169 strncpy( p_debugd->str_target_file_coredump,
170 optarg, DRD64_MAX_PATH );
172 /* "r" : Attach or Debug Request Source FD */
173 else if( 'r' == i_opt ) {
174 if( 0x00 == Drd64_Common_isDigits( optarg ) )
177 { *i_request_fd = atoi( optarg ); }
180 /* "m" : Local Marshald ConnectInfo ID */
181 else if( 'm' == i_opt ) {
182 if( 0x00 == Drd64_Common_isDigits( optarg ) )
185 { p_debugd->i_marshald_connectid = atoi( optarg ); }
188 /* "d" : Debug > Option Debugee FullPath */
189 else if( 'd' == i_opt ) {
190 if( 0 < i_flag_debug )
193 { i_flag_debug = 2; }
197 /* "a" : Attach > Option : Debugee Pid */
198 else if( 'a' == i_opt ) {
199 if( 0x00 == Drd64_Common_isDigits( optarg ) )
202 { p_debugd->i_target_pid = atoi( optarg ); }
213 if(( 'd' == i_opt ) && ( optind < argc )) {
214 strncpy( p_debugd->str_target_file_exec, argv[optind], DRD64_MAX_PATH );
217 if( optind < argc ) {
218 p_debugd->ppstr_argv = argv + optind;
219 p_debugd->i_arg_options = argc - optind;
226 if(( 0x00 != i_err ) || ( 4 > i_options )) {
227 Drd64_Debugd_Main_Usage();
241 /* Phase 1 : Check Booting by Command-Line? ---*/
243 Drd64_Debugd_Main_Usage();
247 /* Phase 2 : Deamonize drd64_debugd ---*/
248 Drd64_Server_Common_Deamonize();
249 /* XXX : Error Proc. */
251 /* Phase 3 : PreInit. drd64_debugd ( Init. LogSystem ) ---*/
252 i_err = Drd64_Debugd_Main_PreInit( &drd64_debugd_info );
253 if( 0x00 != i_err ) { return 0x01; }
254 DRD64_LOG_VERBOSE(" [STAT] Completed Deamonize ");
256 /* Phase 4 : Init. memory & Analyze Option ---*/
259 memset( &drd64_debugd_info, 0x00,
260 sizeof( Drd64_Debugd_MasterInformation ) );
261 drd64_debugd_info.i_socket_client = -1;
262 drd64_debugd_info.i_target_pid = -1;
264 i_err = Drd64_Debugd_Main_AnalyzeOption(
265 &drd64_debugd_info, argc, argv, &i_request_fd );
266 if( 0x00 != i_err ) { return 0x01; }
267 DRD64_LOG_VERBOSE(" [STAT] Completed Analyze Option ");
269 /* Phase 5 : Init. drd64_debugd ---*/
270 i_err = Drd64_Debugd_Main_Init( &drd64_debugd_info, i_request_fd );
271 if( 0x00 != i_err ) {
274 DRD64_LOG_VERBOSE(" [STAT] Completed drd64_debugd System Init. ");
276 /* Phase 6 : Attach or Debug-Start to Debugee Program ---*/
277 i_err = Drd64_Debugd_Debug_Attach( &drd64_debugd_info );
278 if( 0x00 != i_err ) {
281 DRD64_LOG_VERBOSE(" [STAT] Completed Attach. ");
284 DRD64_LOG_VERBOSE("[STAT] Completed Booting drd64_debugd. ");
286 Drd64_Debugd_Dispatch_Polling( &drd64_debugd_info );
293 /* EOF of drd64_.c ----------------------------------- */