<commit_before>//
//  SBDebugger.mm
//  SwiftLLDB
//

#import "SBDebugger.h"
#import "SBTarget.h"
#import "SBTarget+Private.h"
#include "LLDB/LLDB.h"
#include "LLDB/SBDebugger.h"
#include <stdio.h>

@implementation SBDebugger {
    lldb::SBDebugger debugger;
}

- (nonnull id)init {
    self = [super init];
    if (self) {
        self->debugger = lldb::SBDebugger::Create();
    }
    return self;
}

- (void) setAsync: (BOOL)async {
    debugger.SetAsync(async);
}

- (BOOL) isAsync {
    return debugger.GetAsync();
}

- (BOOL) isValid {
    return debugger.IsValid();
}

/// A helper method that returns a pointer to a C FILE for that file handle.
FILE *openFileHanle(NSFileHandle *fileHandle, const char *mode, NSError **error) {
    FILE *inputFile = fdopen([fileHandle fileDescriptor], mode);
    if (!inputFile) {
        if (error) {
            *error = [NSError errorWithDomain:NSPOSIXErrorDomain
                                         code:errno
                                     userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open the file descriptor" }];
        }
        return NULL;
    }
    setbuf(inputFile, NULL);
    return inputFile;
}

- (BOOL) setInputFileHandle: (nonnull NSFileHandle *)fileHandle error:(NSError **)error {
    FILE *f = openFileHanle(fileHandle, "r", error);
    if (!f) { return NO; }
    debugger.SetInputFileHandle(f, /*transfer_ownership=*/false);
    return YES;
}

- (BOOL) setOutputFileHandle: (nonnull NSFileHandle *)fileHandle error:(NSError **)error {
    FILE *f = openFileHanle(fileHandle, "w", error);
    if (!f) { return NO; }
    debugger.SetOutputFileHandle(f, /*transfer_ownership=*/false);
    return YES;
}

- (BOOL) setErrorFileHandle: (nonnull NSFileHandle *)fileHandle error:(NSError **)error {
    FILE *f = openFileHanle(fileHandle, "w", error);
    if (!f) { return NO; }
    debugger.SetErrorFileHandle(f, /*transfer_ownership=*/false);
    return YES;
}

- (NSInteger) getNumTargets {
    return (NSInteger)debugger.GetNumTargets();
}

- (SBTarget *) getSelectedTarget {
    SBTarget *target = [[SBTarget alloc] init];
    lldb::SBTarget llTarget = debugger.GetSelectedTarget();
    [target setTarget: &llTarget];
    return target;
}

- (SBTarget *) getTargetAtIndex: (NSInteger)index {
    SBTarget *target = [[SBTarget alloc] init];
    lldb::SBTarget llTarget  = debugger.GetTargetAtIndex((uint32_t)index);
    [target setTarget: &llTarget];
    return target;
}

- (void) clear {
    debugger.Clear();
}

- (void) handleCommand: (NSString *)command {
    debugger.HandleCommand([command UTF8String]);
}

- (void) runCommandInterpreter: (BOOL)autoHandleEvents spawnThread:(BOOL)spawnThread {
    debugger.RunCommandInterpreter(autoHandleEvents, spawnThread);
}

- (BOOL) runREPL: (LanguageType)languageType options:(nonnull NSString *)replOptions error:(NSError **)error {
    if (error)
        *error = NULL;
    const char *options = [replOptions UTF8String];
    lldb::SBError llerror (debugger.RunREPL(lldb::LanguageType(languageType), options));
    if (llerror.Fail() && error) {
        const char *errorString = llerror.GetCString();
        NSString *description = [NSString stringWithUTF8String:(errorString ? errorString : "")];
        *error = [NSError errorWithDomain:NSPOSIXErrorDomain
                                     code:llerror.GetError()
                                 userInfo:@{ NSLocalizedDescriptionKey: description }];
        return NO;
    }
    return YES;
}

+ (void) setUp {
    lldb::SBDebugger::Initialize();
}

+ (void) tearDown {
    lldb::SBDebugger::Terminate();
}

@end
<commit_msg>Fix typo (found by @mattrajca)<commit_after>//
//  SBDebugger.mm
//  SwiftLLDB
//

#import "SBDebugger.h"
#import "SBTarget.h"
#import "SBTarget+Private.h"
#include "LLDB/LLDB.h"
#include "LLDB/SBDebugger.h"
#include <stdio.h>

@implementation SBDebugger {
    lldb::SBDebugger debugger;
}

- (nonnull id)init {
    self = [super init];
    if (self) {
        self->debugger = lldb::SBDebugger::Create();
    }
    return self;
}

- (void) setAsync: (BOOL)async {
    debugger.SetAsync(async);
}

- (BOOL) isAsync {
    return debugger.GetAsync();
}

- (BOOL) isValid {
    return debugger.IsValid();
}

/// A helper method that returns a pointer to a C FILE for that file handle.
FILE *openFileHandle(NSFileHandle *fileHandle, const char *mode, NSError **error) {
    FILE *inputFile = fdopen([fileHandle fileDescriptor], mode);
    if (!inputFile) {
        if (error) {
            *error = [NSError errorWithDomain:NSPOSIXErrorDomain
                                         code:errno
                                     userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open the file descriptor" }];
        }
        return NULL;
    }
    setbuf(inputFile, NULL);
    return inputFile;
}

- (BOOL) setInputFileHandle: (nonnull NSFileHandle *)fileHandle error:(NSError **)error {
    FILE *f = openFileHandle(fileHandle, "r", error);
    if (!f) { return NO; }
    debugger.SetInputFileHandle(f, /*transfer_ownership=*/false);
    return YES;
}

- (BOOL) setOutputFileHandle: (nonnull NSFileHandle *)fileHandle error:(NSError **)error {
    FILE *f = openFileHandle(fileHandle, "w", error);
    if (!f) { return NO; }
    debugger.SetOutputFileHandle(f, /*transfer_ownership=*/false);
    return YES;
}

- (BOOL) setErrorFileHandle: (nonnull NSFileHandle *)fileHandle error:(NSError **)error {
    FILE *f = openFileHandle(fileHandle, "w", error);
    if (!f) { return NO; }
    debugger.SetErrorFileHandle(f, /*transfer_ownership=*/false);
    return YES;
}

- (NSInteger) getNumTargets {
    return (NSInteger)debugger.GetNumTargets();
}

- (SBTarget *) getSelectedTarget {
    SBTarget *target = [[SBTarget alloc] init];
    lldb::SBTarget llTarget = debugger.GetSelectedTarget();
    [target setTarget: &llTarget];
    return target;
}

- (SBTarget *) getTargetAtIndex: (NSInteger)index {
    SBTarget *target = [[SBTarget alloc] init];
    lldb::SBTarget llTarget  = debugger.GetTargetAtIndex((uint32_t)index);
    [target setTarget: &llTarget];
    return target;
}

- (void) clear {
    debugger.Clear();
}

- (void) handleCommand: (NSString *)command {
    debugger.HandleCommand([command UTF8String]);
}

- (void) runCommandInterpreter: (BOOL)autoHandleEvents spawnThread:(BOOL)spawnThread {
    debugger.RunCommandInterpreter(autoHandleEvents, spawnThread);
}

- (BOOL) runREPL: (LanguageType)languageType options:(nonnull NSString *)replOptions error:(NSError **)error {
    if (error)
        *error = NULL;
    const char *options = [replOptions UTF8String];
    lldb::SBError llerror (debugger.RunREPL(lldb::LanguageType(languageType), options));
    if (llerror.Fail() && error) {
        const char *errorString = llerror.GetCString();
        NSString *description = [NSString stringWithUTF8String:(errorString ? errorString : "")];
        *error = [NSError errorWithDomain:NSPOSIXErrorDomain
                                     code:llerror.GetError()
                                 userInfo:@{ NSLocalizedDescriptionKey: description }];
        return NO;
    }
    return YES;
}

+ (void) setUp {
    lldb::SBDebugger::Initialize();
}

+ (void) tearDown {
    lldb::SBDebugger::Terminate();
}

@end

{'fraction_non_alphanumeric': 0.13540372670807455, 'fraction_numerical': 0.0013802622498274672, 'mean_word_length': 3.3002967359050444, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2190142', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2372, 'n_words': 510}