Skip to content

Commit

Permalink
Implement new NSLog logging handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Apr 15, 2018
1 parent f805a87 commit 4315138
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
3 changes: 3 additions & 0 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#import "AppDelegate.h"
#import "TerminalViewController.h"
#include "kernel/init.h"
// task_create in kernel/task.h conflicts with task_create in mach/task.h
#define task_create fucking_task_create
#include "kernel/calls.h"
#undef task_create

@interface AppDelegate ()

Expand Down
22 changes: 20 additions & 2 deletions debug.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#ifndef DEBUG_H
#define DEBUG_H
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#if LOG_HANDLER_NSLOG
#include <CoreFoundation/CoreFoundation.h>
#endif

// TODO turn this into function that outputs to a log buffer
#define printk(msg, ...) dprintf(666, msg, ##__VA_ARGS__)
static inline void printk(const char *msg, ...) {
va_list args;
va_start(args, msg);
#if LOG_HANDLER_DPRINTF
vdprintf(666, msg, args);
#elif LOG_HANDLER_NSLOG
extern void NSLogv(CFStringRef msg, va_list args);
CFStringRef cfmsg = CFStringCreateWithCStringNoCopy(NULL, msg, kCFStringEncodingUTF8, kCFAllocatorNull);
NSLogv(cfmsg, args);
CFRelease(cfmsg);
#endif
va_end(args);
}

// all line endings should use \r\n so it can work even with the terminal in raw mode
// this is subject to change, so use NEWLINE or println whenever you output a newline
Expand Down Expand Up @@ -87,3 +103,5 @@ extern int log_override;
#include <signal.h>
#define debugger raise(SIGTRAP)
#endif

#endif
22 changes: 8 additions & 14 deletions iSH.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
BB13F7FC200ADDA0003D1C4D /* libgdbm.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BB13F7EF200ADD69003D1C4D /* libgdbm.a */; };
BB13F810200AE716003D1C4D /* libsoftfloat.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BB13F804200AE69D003D1C4D /* libsoftfloat.a */; };
BB455E111FB37F6600AFB48B /* DelayedUITask.m in Sources */ = {isa = PBXBuildFile; fileRef = BB455E101FB37F6600AFB48B /* DelayedUITask.m */; };
BB4A53AA1FAA496700A72ACE /* bundle.js in Resources */ = {isa = PBXBuildFile; fileRef = BB4A53A81FAA496700A72ACE /* bundle.js */; };
BB4A53AB1FAA496700A72ACE /* term.html in Resources */ = {isa = PBXBuildFile; fileRef = BB4A53A91FAA496700A72ACE /* term.html */; };
BB4A53B01FAA787A00A72ACE /* term.css in Resources */ = {isa = PBXBuildFile; fileRef = BB4A53AF1FAA787900A72ACE /* term.css */; };
BB52C03D2083DA3600104515 /* xterm-dist in Resources */ = {isa = PBXBuildFile; fileRef = BB52C03C2083DA3600104515 /* xterm-dist */; };
BB623CF91FA7C68800932047 /* alpine in Resources */ = {isa = PBXBuildFile; fileRef = BBF124901FA7C3100088FB50 /* alpine */; };
BB78AB2B1FAD22440013E782 /* TerminalView.m in Sources */ = {isa = PBXBuildFile; fileRef = BB78AB2A1FAD22440013E782 /* TerminalView.m */; };
BB792B551F96D90D00FFB7A4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BB792B541F96D90D00FFB7A4 /* AppDelegate.m */; };
Expand Down Expand Up @@ -113,7 +111,7 @@
BB0FC5711F98026700803272 /* mm.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = mm.c; sourceTree = "<group>"; };
BB0FC5721F98026700803272 /* mmap.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = mmap.c; sourceTree = "<group>"; };
BB0FC5731F98026700803272 /* poll.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = poll.c; sourceTree = "<group>"; };
BB0FC5741F98026700803272 /* process.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = task.c; sourceTree = "<group>"; };
BB0FC5741F98026700803272 /* task.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = task.c; sourceTree = "<group>"; };
BB0FC5751F98026700803272 /* task.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = task.h; sourceTree = "<group>"; };
BB0FC5761F98026700803272 /* signal.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = signal.c; sourceTree = "<group>"; };
BB0FC5771F98026700803272 /* signal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = signal.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -149,10 +147,9 @@
BB455E101FB37F6600AFB48B /* DelayedUITask.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DelayedUITask.m; sourceTree = "<group>"; };
BB4A539A1FAA411D00A72ACE /* package.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = package.json; sourceTree = "<group>"; };
BB4A539C1FAA490C00A72ACE /* term.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = term.js; sourceTree = "<group>"; };
BB4A539D1FAA490C00A72ACE /* webpack.config.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = webpack.config.js; sourceTree = "<group>"; };
BB4A53A81FAA496700A72ACE /* bundle.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = bundle.js; sourceTree = "<group>"; };
BB4A53A91FAA496700A72ACE /* term.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = term.html; sourceTree = "<group>"; };
BB4A53AF1FAA787900A72ACE /* term.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = term.css; sourceTree = "<group>"; };
BB52C03C2083DA3600104515 /* xterm-dist */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "xterm-dist"; sourceTree = "<group>"; };
BB78AB291FAD22440013E782 /* TerminalView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TerminalView.h; sourceTree = "<group>"; };
BB78AB2A1FAD22440013E782 /* TerminalView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TerminalView.m; sourceTree = "<group>"; };
BB792B501F96D90D00FFB7A4 /* iSH.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iSH.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -304,9 +301,8 @@
BB4A539C1FAA490C00A72ACE /* term.js */,
BB4A53AF1FAA787900A72ACE /* term.css */,
BB4A53A91FAA496700A72ACE /* term.html */,
BB4A539D1FAA490C00A72ACE /* webpack.config.js */,
BB4A539A1FAA411D00A72ACE /* package.json */,
BB4A53A81FAA496700A72ACE /* bundle.js */,
BB52C03C2083DA3600104515 /* xterm-dist */,
);
path = xtermjs;
sourceTree = "<group>";
Expand Down Expand Up @@ -539,13 +535,11 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BB623CF91FA7C68800932047 /* alpine in Resources */,
BB792B601F96D90D00FFB7A4 /* LaunchScreen.storyboard in Resources */,
BB4A53AB1FAA496700A72ACE /* term.html in Resources */,
BB4A53AA1FAA496700A72ACE /* bundle.js in Resources */,
BB792B5D1F96D90D00FFB7A4 /* Assets.xcassets in Resources */,
BB4A53B01FAA787A00A72ACE /* term.css in Resources */,
BB792B601F96D90D00FFB7A4 /* LaunchScreen.storyboard in Resources */,
BB792B5B1F96D90D00FFB7A4 /* Main.storyboard in Resources */,
BB623CF91FA7C68800932047 /* alpine in Resources */,
BB52C03D2083DA3600104515 /* xterm-dist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -606,7 +600,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = "/bin/sh -e";
shellScript = "cd $SRCROOT/app/xtermjs\nwebpack";
shellScript = "cd $SRCROOT/app/xtermjs\nyarn\nyarn build";
};
BBF1248A1FA7BDBA0088FB50 /* Create Alpine Filesystem */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
4 changes: 4 additions & 0 deletions kernel/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#include <sys/resource.h>
#elif __APPLE__
// pull in thread_info and friends
// this also pulls in something called task_create which is different from our
// task_create so JUST SAY NO
#define task_create fucking_task_create
#include <mach/mach.h>
#undef task_create
#else
#error
#endif
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ foreach channel : log_on + log_off
add_project_arguments('-DDEBUG_' + channel + '=0', language: 'c')
endif
endforeach
add_project_arguments('-DLOG_HANDLER_' + get_option('log_handler').to_upper() + '=1', language: 'c')

if get_option('no_crlf')
add_project_arguments('-DNO_CRLF', language: 'c')
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
option('log', type: 'string', value: '')
option('nolog', type: 'string', value: '')
option('log_handler', type: 'string', value: 'dprintf')

option('vdso_c_args', type: 'string', value: '')

Expand Down
4 changes: 2 additions & 2 deletions xcode-meson.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash -x
export
mkdir -p $MESON_BUILD_DIR
cd $MESON_BUILD_DIR

Expand Down Expand Up @@ -37,7 +36,8 @@ if [[ $CONFIGURATION == Release ]]; then
b_ndebug=true
fi
log=$ISH_LOG
for var in buildtype log b_ndebug; do
log_handler=nslog
for var in buildtype log b_ndebug log_handler; do
old_value=$(jq -r ".[] | select(.name==\"$var\") | .value" <<< $config)
new_value=${!var}
if [[ $old_value != $new_value ]]; then
Expand Down

0 comments on commit 4315138

Please sign in to comment.