Is it possible to identify where the kernel function returned using kretprobe or BPF code? For example;
void func()
{
.........some line......
.........some line......
if (condition1)
return;
.........some line......
.........some line......
if(condition2)
return;
.........some line......
if(condition3)
return;
.........some line......
.........some line......
.........some line......
return;
}
If I have a kernel function like this, how would I know which return was hit?
I guess you can create a kprobe on each return line.
If you are the author of the function you try to trace, I'd just set a global variable to certain value for each branch taken.
Related
Trying to experiment with egui and macroquad, but can't get elements enabled for edit.
From the standard example:
use macroquad::prelude::*;
#[macroquad::main("")]
async fn main() {
loop {
clear_background(BLACK);
egui_macroquad::ui(|egui_ctx| {
egui_macroquad::egui::Window::new("egui ❤ macroquad").show(egui_ctx, |ui| {
ui.colored_label(egui_macroquad::egui::Color32::WHITE, "Test");
ui.add(egui_macroquad::egui::TextEdit::singleline(&mut "ku").text_color(egui_macroquad::egui::Color32::RED));
});
});
egui_macroquad::draw();
next_frame().await
}
}
In Cargo.toml:
[dependencies]
macroquad = "0.3.25"
egui-macroquad = "0.12.0"
As result:
I see the TextEdit::singleline widget, but can't edit it.
Should I enable it somehow or something else?
Found the solution. Mutable "String" variable must be defined and used for TextEdit::singleline:
use macroquad::prelude::*;
#[macroquad::main("")]
async fn main() {
let mut kuku: String = "ku".to_string();
loop {
clear_background(BLACK);
egui_macroquad::ui(|egui_ctx| {
egui_macroquad::egui::Window::new("egui ❤ macroquad").show(egui_ctx, |ui| {
ui.colored_label(egui_macroquad::egui::Color32::WHITE, "Test");
ui.add(egui_macroquad::egui::TextEdit::singleline(&mut kuku).text_color(egui_macroquad::egui::Color32::RED));
});
});
egui_macroquad::draw();
next_frame().await
}
}
Now it works, because it takes the values from the widget and assign them to the variable "kuku".
I have a kotlinjs app. I handle a particular event (dropping of data onto a component) like this:
onEvent {
drop = { event ->
GlobalScope.async {
//...
dropTask(y, data)
}
}
}
// ...
// this function has to be a suspend function because model's is
private suspend fun dropTask(y: Int, taskId: TaskId) {
// ... prepare data
model.insertBefore(taskId!!, insertBefore?.id)
}
// ... Model's function is defined like this:
suspend fun insertBefore(taskToInsert: TaskId, taskBefore: TaskId?) {
val (src, _) = memory.find(taskToInsert)
// ... and finally, the find function is:
fun find(taskId: TaskId): Pair<Task?, Int> {
// ...
return if (task != null) {
// ...
} else {
throw Exception("Couldn't find task with id $taskId!!")
}
}
The issue is that the Exception gets thrown, but isn't reported anywhere.
I have tried:
a) Installing a CoroutineExceptionHandler into the GlobalScope.async (i.e.:
val handler = CoroutineExceptionHandler { _, e ->
console.log("Caught exception: $e")
}
GlobalScope.async(handler) {
...but this never gets called. This would be relatively clean if I could make it work. It would be even nicer if this was default behavior for kotlinjs, so that exceptions weren't accidentally unreported.
b) Calling await:
drop = { event ->
GlobalScope.launch {
GlobalScope.async() {
// ...
dropTask(y, data)
}.await()
}
}
This does result in the exception being logged to the console, but it's so ugly. It's not possible to call .await() outside of a suspend function or coroutine, so for this particular event handler I have to wrap the async call in a launch. I must be doing something wrong. Anybody have a better pattern that I should be using?
I get a HTML page from my NodeJS instance with the signature:
public func requestHTMLPage(_ page: String) -> Observable<String?>
but I've got some cached HTML pages so want to return them.
I'd like to return my cached page
if let cachedPage = cachedPage {
return BehaviorSubject<String?>(value: data)
}
but unfortunately it does not tell my subscribers that the data is returned.
I've used the following awful solution:
if let cachedPage = cachedPage {
observer.onNext(data)
return BehaviorSubject<String?>(value: data)
}
as I want to tell my observer we have the data, but also I want to return as we are at the end of this path of execution.
How can I return and give the type Observable after I have made my observer.onNext, or how can I return with just observer.onNext?
I'm not sure why you try to use a Subject here, you probably simple need to use Observable.create:
public func requestHTMLPage(_ page: String) -> Observable<String?> {
return Observable.create { observer in
if cachedPage = self.cache[page] {
observer.onNext(cachedPage)
observer.onCompleted()
return Disposables.create()
} else {
/* whatever you use to fetch the data in a reactive way */
return self.service.rx.request(page).subscribe(observer)
}
}
}
Depending on where this code is, pay attention to retain cycles.
Looking at the example here at Message Controller for Pizza Example, if I want to populate Size or Kind based on some user input and make a call to the database, how would I do that?
So far as I know, there is not an easy way to populate the Enum at runtime.
It looks like this hasn't been implemented yet. I took a look inside https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/FormFlow/FormBuilder.cs and found this:
internal static void TypePaths(Type type, string path, List<string> paths)
{
if (type.IsClass)
{
if (type == typeof(string))
{
paths.Add(path);
}
else if (type.IsIEnumerable())
{
var elt = type.GetGenericElementType();
if (elt.IsEnum)
{
paths.Add(path);
}
else
{
// TODO: What to do about enumerations of things other than enums?
}
}
else
{
FieldPaths(type, path, paths);
}
}
else if (type.IsEnum)
{
paths.Add(path);
}
else if (type == typeof(bool))
{
paths.Add(path);
}
else if (type.IsIntegral())
{
paths.Add(path);
}
else if (type.IsDouble())
{
paths.Add(path);
}
else if (type.IsNullable() && type.IsValueType)
{
paths.Add(path);
}
else if (type == typeof(DateTime))
{
paths.Add(path);
}
}
Notice the TODO about enumerations other than enums.
Outside of the FormBuilder we can use PromptDialog.Choice which takes an IEnumerable<> of your options.
It is possible to chain dialogs together, so you may have to split your FormDialog into two with the PromptDialog in-between.
Alternatively take a fork of BotBuilder and implement the TODO!
I cannot figure out why this will not compile.
It says functions ends without a return statement, but when I add a return after the else, it still won't compile.
func (d Foo) primaryOptions() []string{
if(d.Line == 1){
return []string{"me", "my"}
}
else{
return []string{"mee", "myy"}
}
}
Go forces else to be on the same line as the if brace.. because of its "auto-semicolon-insertion" rules.
So it must be this:
if(d.Line == 1) {
return []string{"me", "my"}
} else { // <---------------------- this must be up here
return []string{"mee", "myy"}
}
Otherwise, the compiler inserts a semicolon for you:
if(d.Line == 1) {
return []string{"me", "my"}
}; // <---------------------------the compiler does this automatically if you put it below
else {
return []string{"mee", "myy"}
}
..hence your error. I will link to the relevant documentation shortly.
EDIT: Effective Go has information regarding this.