Add netdbg

This commit is contained in:
Sergi Granell 2016-01-23 14:02:41 +01:00
parent 17293cdb86
commit 7003df5133
6 changed files with 126 additions and 11 deletions

View File

@ -22,10 +22,19 @@ LIBS = -lvita2d -lpng -ljpeg -lz -lm -lc \
-lSceSysmodule_stub -lScePower_stub -lSceTouch_stub -lScePgf_stub \
-lScePvf_stub -lUVLoader_stub
#NETDBG_IP ?= 192.168.1.50
ifdef NETDBG_IP
CFLAGS += -DNETDBG_ENABLE=1 -DNETDBG_IP="\"$(NETDBG_IP)\""
endif
ifdef NETDBG_PORT
CFLAGS += -DNETDBG_PORT=$(NETDBG_PORT)
endif
PREFIX = arm-vita-eabi
CC = $(PREFIX)-gcc
CXX = $(PREFIX)-g++
CFLAGS = -Wl,-q -Wall -O3 -Wno-unused-variable -Wno-unused-but-set-variable \
CFLAGS += -Wl,-q -Wall -O3 -Wno-unused-variable -Wno-unused-but-set-variable \
$(foreach dir, $(FEXDIRS), -I$(dir))
CXXFLAGS = $(CFLAGS) -std=c++11 -fno-rtti -fno-exceptions
ASFLAGS = $(CFLAGS)

View File

@ -45,8 +45,8 @@ typedef struct {
int sceGenSyscall();
void _init_vita_heap();
void _free_vita_heap();
void _init_vita_newlib();
void _free_vita_newlib();
int sceKernelGetProcessId();
@ -73,4 +73,4 @@ int sceKernelGetFreeMemorySize(param);
int sceKernelGetSystemSwVersion(SwVersionParam *param);
int sceKernelGetModelForCDialog();
#endif
#endif

View File

@ -349,8 +349,8 @@ void loadElf(char *file) {
}
/*
// Init heap
_init_vita_heap();
// Init libc
_init_vita_newlib();
// Load language
loadLanguage(language);
@ -632,7 +632,7 @@ SceUID sceKernelCreateThreadPatchedUVL(const char *name, SceKernelThreadEntry en
makeFunctionStub(findModuleImportByInfo(&hb_mod_info, hb_text_addr, "SceLibKernel", 0x7595D9AA), info.mappedBase);
restoreUVL();
_free_vita_heap();
_free_vita_newlib();
} else {
exit_thid = sceKernelCreateThread("exit_thread", (SceKernelThreadEntry)exit_thread, 0x10000100, 0x1000, 0, 0, NULL);
if (exit_thid >= 0)

11
main.c
View File

@ -1295,7 +1295,7 @@ int sceKernelTrySendMsgPipePatched(SceUID uid, void *message, unsigned int size,
*(uint32_t *)(buffer + 0x00) = 0x40000; // Changing output size
//*(uint32_t *)(buffer + 0x10) = 0x4000;
}
memset(buffer, -1, size);
}
@ -1499,7 +1499,7 @@ void freePreviousVitaShell() {
}
}
int user_thread(SceSize args, void *argp) {
int vitashell_thread(SceSize args, void *argp) {
#ifndef RELEASE
// sceIoRemove("cache0:vitashell_log.txt");
#endif
@ -1509,8 +1509,9 @@ int user_thread(SceSize args, void *argp) {
// Init VitaShell
VitaShellInit();
netdbg_init();
debugPrintf("Main\n");
listMemBlocks(0x60000000, 0xF0000000);
//listMemBlocks(0x60000000, 0xF0000000);
// Set up nid table
// setupNidTable();
@ -1545,12 +1546,14 @@ int user_thread(SceSize args, void *argp) {
finishVita2dLib();
finishSceAppUtil();
netdbg_fini();
return sceKernelExitDeleteThread(0);
}
int main() {
// Start app with bigger stack
SceUID thid = sceKernelCreateThread("user_thread", (SceKernelThreadEntry)user_thread, 0x10000100, 1 * 1024 * 1024, 0, 0x70000, NULL);
SceUID thid = sceKernelCreateThread("VitaShell_main_thread", (SceKernelThreadEntry)vitashell_thread, 0x10000100, 1 * 1024 * 1024, 0, 0x70000, NULL);
if (thid >= 0) {
sceKernelStartThread(thid, 0, NULL);
sceKernelWaitThreadEnd(thid, NULL, NULL);

97
utils.c
View File

@ -25,6 +25,12 @@
SceCtrlData pad;
uint32_t old_buttons, current_buttons, pressed_buttons, hold_buttons, hold2_buttons, released_buttons;
#define NET_INIT_SIZE 1*1024*1024
static int netdbg_sock = -1;
static void *net_memory = NULL;
static int net_init = -1;
void errorDialog(int error) {
initMessageDialog(SCE_MSG_DIALOG_BUTTON_TYPE_OK, language_container[ERROR], error);
dialog_step = DIALOG_STEP_ERROR;
@ -45,6 +51,7 @@ int debugPrintf(char *text, ...) {
va_end(list);
uvl_log_write(string, strlen(string));
netdbg(string);
SceUID fd = sceIoOpen("cache0:vitashell_log.txt", SCE_O_WRONLY | SCE_O_CREAT | SCE_O_APPEND, 0777);
if (fd >= 0) {
@ -194,3 +201,93 @@ void getTimeString(char *string, int time_format, SceRtcTime *time) {
break;
}
}
int netdbg_init()
{
#ifdef NETDBG_ENABLE
int ret;
SceNetSockaddrIn server;
SceNetInitParam initparam;
SceUShort16 port = NETDBG_DEFAULT_PORT;
#ifdef NETDBG_PORT
port = NETDBG_PORT;
#endif
/* Init Net */
ret = sceNetShowNetstat();
if (ret == SCE_NET_ERROR_ENOTINIT) {
net_memory = malloc(NET_INIT_SIZE);
initparam.memory = net_memory;
initparam.size = NET_INIT_SIZE;
initparam.flags = 0;
ret = net_init = sceNetInit(&initparam);
if (net_init < 0)
goto error_netinit;
} else if (ret != 0) {
goto error_netstat;
}
server.sin_len = sizeof(server);
server.sin_family = SCE_NET_AF_INET;
sceNetInetPton(SCE_NET_AF_INET, NETDBG_IP, &server.sin_addr);
server.sin_port = sceNetHtons(port);
memset(server.sin_zero, 0, sizeof(server.sin_zero));
ret = netdbg_sock = sceNetSocket("VitaShell_netdbg", SCE_NET_AF_INET, SCE_NET_SOCK_STREAM, 0);
if (netdbg_sock < 0)
goto error_netsock;
ret = sceNetConnect(netdbg_sock, (SceNetSockaddr *)&server, sizeof(server));
if (ret < 0)
goto error_netconnect;
return 0;
error_netconnect:
sceNetSocketClose(netdbg_sock);
netdbg_sock = -1;
error_netsock:
if (net_init == 0) {
sceNetTerm();
net_init = -1;
}
error_netinit:
if (net_memory) {
free(net_memory);
net_memory = NULL;
}
error_netstat:
return ret;
#endif
}
void netdbg_fini()
{
if (netdbg_sock > 0) {
sceNetSocketClose(netdbg_sock);
if (net_init == 0)
sceNetTerm();
if (net_memory)
free(net_memory);
netdbg_sock = -1;
net_init = -1;
net_memory = NULL;
}
}
int netdbg(const char *text, ...)
{
va_list list;
char string[512];
if (netdbg_sock > 0) {
va_start(list, text);
vsprintf(string, text, list);
va_end(list);
return sceNetSend(netdbg_sock, string, strlen(string), 0);
}
return -1;
}

View File

@ -63,4 +63,10 @@ void getSizeString(char *string, uint64_t size);
void getDateString(char *string, int date_format, SceRtcTime *time);
void getTimeString(char *string, int time_format, SceRtcTime *time);
#define NETDBG_DEFAULT_PORT 9023
int netdbg_init();
void netdbg_fini();
int netdbg(const char *text, ...);
#endif